<template>
  <div class="view-fill">
    <div class="app-container-flex">
      <NewFullScreen
        v-model="showDialog"
        :title="'批量建卡'"
        :btnList="fullInfo.btnList"
        @returnBack="emits('returnModify')"
      >
        <el-empty
          v-if="tableInfo.data.length === 0"
          description="暂无数据"
        ></el-empty>
        <el-tabs
          v-else
          tab-position="left"
          type="card"
          @tab-click="handleClick"
          :before-leave="beforeLeave"
          class="tabs"
          v-model="activeName"
        >
          <template v-for="(item, index) in tableInfo.data" :key="index">
            <el-tab-pane :name="String(index)">
              <template #label>
                <li class="el-tab-pane-li">单号：{{ item.orderNo }}</li>
                <li class="el-tab-pane-li commonName">
                  资产名称：{{ item.commonName }}
                </li>
                <li class="el-tab-pane-li">
                  建卡数量：{{ item.canBuildCardCalcQty }}
                </li>
              </template>
              <div class="box-scroll-y">
                <div class="model-panel">
                  <div class="model-panel-title">
                    <p>{{ $t('basic_information') }}</p>
                  </div>
                  <div class="model-panel-body">
                    <page-form
                      class="paddingBox order-model-formBox flex_wrap_start_start"
                      v-model:ref-obj="formInfo['baseRef' + index]"
                      :data="formInfo.data"
                      :field-list="formInfo.baseInfoFieldList"
                      :rules="formInfo.baseInfoRules"
                      :label-width="formInfo.labelWidth"
                      :list-type-info="listTypeInfo"
                      :image-field="formInfo.imageField"
                      @handleEvent="handleEventBaseForm"
                    >
                      <template v-slot:form-assetFileUrlList>
                        <upload-img
                          v-model:value="formInfo.data.assetFileUrlList"
                          multiple
                          :action="formInfo.imageField.action"
                          title="资产文档"
                          :file-type="formInfo.fileType"
                          :response-fn="handleResponse"
                          :limit="10"
                          :showName="true"
                        />
                      </template>
                      <template v-slot:form-depotName>
                        <el-input
                          v-model="formInfo.data.depotName"
                          type="input"
                          :disabled="true"
                          placeholder="请选择仓库"
                        >
                          <!-- <template #append>
                            <el-icon @click="openDepotWindow"
                              ><MoreFilled
                            /></el-icon>
                          </template> -->
                        </el-input>
                      </template>
                      <template v-slot:form-supplierName>
                        <el-input
                          v-if="Number(formInfo.data.temporaryPurch) === 0"
                          type="input"
                          :disabled="true"
                          placeholder="请选择供应商"
                          :class="
                            formInfo.data.disabledSupplier ? '' : 'not-mongolia'
                          "
                          v-model="formInfo.data.supplierName"
                        >
                          <template
                            #append
                            v-if="!formInfo.data.disabledSupplier"
                          >
                            <el-icon @click="openSupplierWindow"
                              ><MoreFilled
                            /></el-icon>
                          </template>
                        </el-input>
                        <el-input
                          v-else
                          v-model="formInfo.data.supplierName"
                          placeholder="请选择供应商"
                        />
                      </template>

                      <template v-slot:form-deviceTypeValue>
                        <el-input
                          v-model="formInfo.data.deviceTypeValue"
                          type="input"
                          :disabled="true"
                          class="not-mongolia"
                          placeholder="请选择医疗器械分类目录"
                        >
                          <template #append>
                            <el-icon @click="openDeviceTypeWindow"
                              ><MoreFilled
                            /></el-icon>
                          </template>
                        </el-input>
                      </template>

                      <template v-slot:form-useDeptName>
                        <el-input
                          v-model="formInfo.data.useDeptName"
                          type="input"
                          :disabled="true"
                          placeholder="请选择使用部门"
                        >
                          <!-- <template #append v-if="!formInfo.data.useDeptName">
                            <el-icon @click="openUseDeptWindow"
                              ><MoreFilled
                            /></el-icon>
                          </template> -->
                        </el-input>
                      </template>

                      <template v-slot:form-manageDeptName>
                        <el-input
                          v-model="formInfo.data.manageDeptName"
                          type="input"
                          :disabled="true"
                          :class="'not-mongolia'"
                          placeholder="请选择管理部门"
                        >
                          <template #append>
                            <el-icon @click="openManageDeptWindow"
                              ><MoreFilled
                            /></el-icon>
                          </template>
                        </el-input>
                      </template>
                      <template v-slot:form-classifyTypeValue>
                        <el-input
                          v-model="formInfo.data.classifyTypeValue"
                          :class="'not-mongolia'"
                          type="input"
                          :disabled="true"
                          placeholder="请选择资产分类"
                        >
                          <template #append>
                            <el-icon @click="openAssetClassifyWindow"
                              ><MoreFilled
                            /></el-icon>
                          </template>
                        </el-input>
                      </template>
                      <template v-slot:form-financialClassifyTypeValue>
                        <el-input
                          v-model="formInfo.data.financialClassifyTypeValue"
                          type="input"
                          :disabled="true"
                          :class="'not-mongolia'"
                          placeholder="请选择资产财务分类"
                        >
                          <template #append>
                            <el-icon @click="openFinanceTypeWindow"
                              ><MoreFilled
                            /></el-icon>
                          </template>
                        </el-input>
                      </template>
                      <template v-slot:form-associatedSubcard>
                        <!-- //  组件/部件  关联子卡片 -->
                        <associatedSubcard
                          ref="associatedSubcardTableForm"
                          :type="type"
                          :assetResourceVOList="
                            formInfo.data.assetResourceVOList
                          "
                        />
                      </template>
                      <template v-slot:form-assetCapitalSourceVOList>
                        <el-form
                          :model="formInfo"
                          :ref="'assetCapitalSourceTableForm' + index"
                          style="width: 100%"
                        >
                          <page-table
                            v-model:data="
                              formInfo.data.assetCapitalSourceVOList
                            "
                            :pager="false"
                            :check-box="false"
                            :tab-index="true"
                            :summary="true"
                            :summaryFieldList="
                              assetCapitalSourceTableInfo.summaryFieldList
                            "
                            :field-list="assetCapitalSourceTableInfo.fieldList"
                            :handle="assetCapitalSourceTableInfo.handle"
                          >
                            <template v-slot:col-code="scope">
                              <el-form-item
                                style="min-width: 100% !important"
                                :prop="`data.assetCapitalSourceVOList.${scope.$index}.code`"
                                :rules="
                                  scope.$index >= 0
                                    ? [
                                        {
                                          required: true,
                                          message: '请选择项目类型',
                                          trigger: 'change',
                                        },
                                      ]
                                    : []
                                "
                              >
                                <select-model
                                  v-model.lazy="scope.row.code"
                                  width="100%"
                                  :type-code="`asset_capital_source`"
                                  :clearable="true"
                                  @change="
                                    changeCapitalSource($event, scope.$index)
                                  "
                                />
                              </el-form-item>
                            </template>
                            <template v-slot:col-amount="scope">
                              <el-form-item
                                style="min-width: 100% !important"
                                :prop="`data.assetCapitalSourceVOList.${scope.$index}.amount`"
                                :rules="
                                  scope.$index >= 0
                                    ? [
                                        {
                                          validator:
                                            $validate.positiveMoneyZeroAsset,
                                          trigger: ['blur', 'change'],
                                        },
                                      ]
                                    : []
                                "
                              >
                                <el-input-number
                                  v-model.lazy="scope.row.amount"
                                  style="width: 100%; display: block"
                                  clearable
                                  controls-position="right"
                                  :precision="
                                    $store.state.permission.systemConfig
                                      .assets_price_precision
                                  "
                                  :min="0"
                                  :max="999999999999999"
                                  @input.native="
                                    changeValidate(
                                      $event,
                                      `data.assetCapitalSourceVOList.${scope.$index}.amount`,
                                      'assetCapitalSourceTableForm'
                                    )
                                  "
                                />
                              </el-form-item>
                            </template>
                            <template v-slot:col-capitalProjectList="scope">
                              <el-input
                                v-model="scope.row.capitalProjectName"
                                type="input"
                                :disabled="true"
                                :class="'not-mongolia'"
                                placeholder="请选择资金项目"
                              >
                                <template #append>
                                  <el-icon
                                    @click="
                                      openAssetCapitalProjectList(scope.$index)
                                    "
                                    ><MoreFilled
                                  /></el-icon>
                                </template>
                              </el-input>
                            </template>
                          </page-table>
                        </el-form>
                      </template>
                    </page-form>
                  </div>
                </div>
                <div class="model-panel">
                  <div class="model-panel-title">
                    <p>{{ $t('common_information') }}</p>
                  </div>
                  <div class="model-panel-body">
                    <page-form
                      class="paddingBox order-model-formBox flex_wrap_start_start"
                      v-model:ref-obj="formInfo['commonRef' + index]"
                      :data="formInfo.data"
                      :field-list="formInfo.commonInfoFieldList"
                      :rules="formInfo.commonRules"
                      :label-width="formInfo.labelWidth"
                      :list-type-info="listTypeInfo"
                    >
                      <template v-slot:form-keeperUserName>
                        <el-input
                          v-model="formInfo.data.keeperUserName"
                          type="input"
                          :disabled="true"
                          class="not-mongolia"
                          placeholder="请选择保管人"
                        >
                          <template #append>
                            <el-icon @click="openKeeperUserList"
                              ><MoreFilled
                            /></el-icon>
                          </template>
                        </el-input>
                      </template>
                      <template v-slot:form-acceptanceUserName>
                        <el-input
                          v-model="formInfo.data.acceptanceUserName"
                          type="input"
                          :disabled="true"
                          class="not-mongolia"
                          placeholder="请选择验收人"
                        >
                          <template #append>
                            <el-icon @click="openAcceptanceUserList"
                              ><MoreFilled
                            /></el-icon>
                          </template>
                        </el-input>
                      </template>
                      <template v-slot:form-purchUserName>
                        <el-input
                          v-model="formInfo.data.purchUserName"
                          type="input"
                          :disabled="true"
                          class="not-mongolia"
                          placeholder="请选择采购人"
                        >
                          <template #append>
                            <el-icon @click="openPurchUserList"
                              ><MoreFilled
                            /></el-icon>
                          </template>
                        </el-input>
                      </template>
                      <template v-slot:form-applicationUserName>
                        <el-input
                          v-model="formInfo.data.applicationUserName"
                          type="input"
                          :disabled="true"
                          class="not-mongolia"
                          placeholder="请选择领用人"
                        >
                          <template #append>
                            <el-icon @click="openApplicationUserList"
                              ><MoreFilled
                            /></el-icon>
                          </template>
                        </el-input>
                      </template>
                      <template v-slot:form-receiveUserName>
                        <el-input
                          v-model="formInfo.data.receiveUserName"
                          type="input"
                          :disabled="true"
                          class="not-mongolia"
                          placeholder="请选择接收人"
                        >
                          <template #append>
                            <el-icon @click="openReceiveUserList"
                              ><MoreFilled
                            /></el-icon>
                          </template>
                        </el-input>
                      </template>
                      <template v-slot:form-useUserName>
                        <el-input
                          v-model="formInfo.data.useUserName"
                          type="input"
                          :disabled="true"
                          class="not-mongolia"
                          placeholder="请选择使用人"
                        >
                          <template #append>
                            <el-icon @click="openUseUserList"
                              ><MoreFilled
                            /></el-icon>
                          </template>
                        </el-input>
                      </template>
                      <template v-slot:form-responsibleUserName>
                        <el-input
                          v-model="formInfo.data.responsibleUserName"
                          type="input"
                          :disabled="true"
                          class="not-mongolia"
                          placeholder="请选择责任人"
                        >
                          <template #append>
                            <el-icon @click="openResponsibleUserList"
                              ><MoreFilled
                            /></el-icon>
                          </template>
                        </el-input>
                      </template>
                    </page-form>
                  </div>
                </div>
                <div
                  class="model-panel"
                  v-if="formInfo.data.isFinanceAsset == 1 ? true : false"
                >
                  <div class="model-panel-title">
                    <p>{{ $t('finance_information') }}</p>
                  </div>
                  <div class="model-panel-body">
                    <page-form
                      class="paddingBox order-model-formBox flex_wrap_start_start"
                      v-model:ref-obj="formInfo['financeRef' + index]"
                      :data="formInfo.data"
                      :field-list="formInfo.financeInfoFieldList"
                      :rules="formInfo.financeInfoRules"
                      :label-width="formInfo.labelWidth"
                      :list-type-info="listTypeInfo"
                      @handleEvent="handleEvent"
                    >
                      <template v-slot:form-postingDate>
                        <el-date-picker
                          v-model="formInfo.data.postingDate"
                          type="date"
                          value-format="YYYY-MM-DD"
                          :disabled-date="
                            productionTimePickerOptions.disabledDate
                          "
                          placeholder="选择日期"
                        >
                        </el-date-picker>
                      </template>
                      <template v-slot:form-assetAmortizationDeptVOList>
                        <el-form
                          :model="formInfo"
                          ref="assetAmortizationDeptTableForm"
                          style="width: 90%"
                        >
                          <page-table
                            :refresh="assetAmortizationDeptTableInfo.refresh"
                            :init-curpage="
                              assetAmortizationDeptTableInfo.initCurpage
                            "
                            v-model:data="
                              formInfo.data.assetAmortizationDeptVOList
                            "
                            :api="assetAmortizationDeptTableInfo.api"
                            :pager="false"
                            :check-box="false"
                            :tab-index="true"
                            :query="assetAmortizationDeptTableInfo.query"
                            :field-list="
                              assetAmortizationDeptTableInfo.fieldList
                            "
                            :handle="assetAmortizationDeptTableInfo.handle"
                            @handleEvent="handleEvent"
                          >
                            <template v-slot:col-amortizationDeptName="scope">
                              <el-form-item
                                :prop="`data.assetAmortizationDeptVOList.${scope.$index}.amortizationDeptName`"
                                :rules="
                                  scope.$index >= 0
                                    ? [
                                        {
                                          required:
                                            formInfo.data.isFinanceAsset &&
                                            !(
                                              formInfo.data.useStatus == 1 &&
                                              formInfo.data.accrualMark == 1
                                            )
                                              ? true
                                              : false,
                                          message: '请选择摊销部门',
                                          trigger: 'change',
                                        },
                                      ]
                                    : []
                                "
                              >
                                <el-input
                                  style="width: 100%"
                                  v-model="scope.row.amortizationDeptName"
                                  type="input"
                                  :disabled="true"
                                  :class="'not-mongolia'"
                                  placeholder="请选择摊销部门"
                                >
                                  <template #append>
                                    <el-icon
                                      @click="
                                        openAmortizationDept(scope.$index)
                                      "
                                      ><MoreFilled
                                    /></el-icon>
                                  </template>
                                </el-input>
                              </el-form-item>
                            </template>
                            <template v-slot:col-amortizationRate="scope">
                              <el-form-item
                                :prop="`data.assetAmortizationDeptVOList.${scope.$index}.amortizationRate`"
                                :rules="
                                  scope.$index >= 0
                                    ? [
                                        {
                                          required: true,
                                          validator: $validate.positiveScore,
                                          trigger: ['blur', 'change'],
                                        },
                                      ]
                                    : []
                                "
                              >
                                <el-input-number
                                  style="width: 100%"
                                  v-model.lazy="scope.row.amortizationRate"
                                  clearable
                                  controls-position="right"
                                  :min="0"
                                  :max="100"
                                  :precision="2"
                                />
                              </el-form-item>
                            </template>
                          </page-table>
                        </el-form>
                      </template>
                    </page-form>
                  </div>
                </div>
                <div
                  class="model-panel"
                  v-if="formInfo.data.isMaintenance == 1 ? true : false"
                >
                  <div class="model-panel-title">
                    <p>{{ $t('maintenance_information') }}</p>
                  </div>
                  <div class="model-panel-body">
                    <page-form
                      class="paddingBox order-model-formBox flex_wrap_start_start"
                      v-model:ref-obj="formInfo['maintenanceRef' + index]"
                      :data="formInfo.data"
                      :field-list="formInfo.maintenanceInfoFieldList"
                      :label-width="formInfo.labelWidth"
                      :rules="formInfo.maintenanceInfoRules"
                      :list-type-info="listTypeInfo"
                      @handleEvent="handleEvent"
                    >
                      <template v-slot:form-maintenanceProviderName>
                        <el-input
                          type="input"
                          :disabled="true"
                          class="not-mongolia"
                          placeholder="请选择维保商"
                          v-model="formInfo.data.maintenanceProviderName"
                        >
                          <template #append>
                            <el-icon @click="openMaintenanceProviderWindow"
                              ><MoreFilled
                            /></el-icon>
                          </template>
                        </el-input>
                      </template>
                      <template v-slot:form-maintenanceContactsName>
                        <el-input
                          v-model="formInfo.data.maintenanceContactsName"
                          type="input"
                          :disabled="true"
                          :class="
                            maintenanceContactsDisabled ? '' : 'not-mongolia'
                          "
                          placeholder="请选择维保商联系人"
                        >
                          <template #append>
                            <el-icon @click="openMaintenanceContactsList"
                              ><MoreFilled
                            /></el-icon>
                          </template>
                        </el-input>
                      </template>
                      <template v-slot:form-hospitalMaintainerUserName>
                        <el-input
                          v-model="formInfo.data.hospitalMaintainerUserName"
                          type="input"
                          :disabled="true"
                          class="not-mongolia"
                          placeholder="请选择院内维保人"
                        >
                          <template #append>
                            <el-icon @click="openHospitalMaintainerUserList"
                              ><MoreFilled
                            /></el-icon>
                          </template>
                        </el-input>
                      </template>
                    </page-form>
                  </div>
                </div>
                <div
                  class="model-panel"
                  v-if="formInfo.data.isMetering == 1 ? true : false"
                >
                  <div class="model-panel-title">
                    <p>{{ $t('measurement_information') }}</p>
                  </div>
                  <div class="model-panel-body">
                    <page-form
                      class="paddingBox order-model-formBox flex_wrap_start_start"
                      v-model:ref-obj="formInfo['measurementRef' + index]"
                      :data="formInfo.data"
                      :field-list="formInfo.measurementInfoFieldList"
                      :label-width="formInfo.labelWidth"
                      :rules="formInfo.measurementInfoRules"
                      :list-type-info="listTypeInfo"
                      @handleEvent="handleEvent"
                    >
                      <template v-slot:form-verificationDate>
                        <el-date-picker
                          v-model="formInfo.data.verificationDate"
                          value-format="YYYY-MM-DD"
                          :disabled-date="checkTimePickerOptions.disabledDate"
                        />
                      </template>
                    </page-form>
                  </div>
                </div>
              </div>
            </el-tab-pane>
          </template>
        </el-tabs>
      </NewFullScreen>
    </div>

    <select-dept
      v-if="selectUseDeptInfo.visible"
      v-model:show-dialog="selectUseDeptInfo.visible"
      :query="selectUseDeptInfo.query"
      :check-box="false"
      :highlight-row="true"
      :saveEmpty="true"
      :api="getDeptsSelectPageAndMaintenanceGroup"
      @callback="selectUseDeptCallback"
    />
    <select-dept
      v-if="selectCommonDeptInfo.visible"
      v-model:show-dialog="selectCommonDeptInfo.visible"
      :query="selectCommonDeptInfo.query"
      :check-box="false"
      :saveEmpty="true"
      :highlight-row="true"
      @callback="selectCommonDeptCallback"
    />

    <select-dept
      v-if="addAssetAmortizationDeptInfo.visible"
      v-model:show-dialog="addAssetAmortizationDeptInfo.visible"
      :query="addAssetAmortizationDeptInfo.query"
      :saveEmpty="true"
      :checkBox="false"
      :highlight-row="true"
      @callback="selectAssetAmortizationDeptCallback"
    />
    <select-supplier
      v-if="selectProductSupplier.visible"
      v-model:show-dialog="selectProductSupplier.visible"
      :query="selectProductSupplier.query"
      :check-box="false"
      :saveEmpty="true"
      :highlight-row="true"
      :api="selectProductSupplier.api"
      @callback="selectSupplierCallback"
    />
    <select-maintenance
      v-if="selectMaintenanceProvider.visible"
      v-model:show-dialog="selectMaintenanceProvider.visible"
      :query="selectMaintenanceProvider.query"
      :check-box="false"
      :saveEmpty="true"
      :highlight-row="true"
      @callback="selectMaintenanceProviderCallback"
    />

    <Select-users
      v-if="selectKeeperUserInfo.visible"
      v-model:showDialog="selectKeeperUserInfo.visible"
      :query="selectKeeperUserInfo.query"
      :api="getRrgUserList"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectKeeperUserCallBack"
    />

    <Select-users
      v-if="selectAcceptanceUserInfo.visible"
      v-model:showDialog="selectAcceptanceUserInfo.visible"
      :query="selectAcceptanceUserInfo.query"
      :api="getRrgUserList"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectAcceptanceUserCallBack"
    />
    <Select-users
      v-if="selectPurchUserInfo.visible"
      v-model:showDialog="selectPurchUserInfo.visible"
      :query="selectPurchUserInfo.query"
      :api="getRrgUserList"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectPurchUserCallBack"
    />
    <Select-users
      v-if="selectApplicationUserInfo.visible"
      v-model:showDialog="selectApplicationUserInfo.visible"
      :query="selectApplicationUserInfo.query"
      :api="getRrgUserList"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectApplicationUserCallBack"
    />
    <Select-users
      v-if="selectReceiveUserInfo.visible"
      v-model:showDialog="selectReceiveUserInfo.visible"
      :query="selectReceiveUserInfo.query"
      :api="getRrgUserList"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectReceiveUserCallBack"
    />
    <selectMaintenanceUsers
      v-if="selectMaintenanceContactsInfo.visible"
      v-model:showDialog="selectMaintenanceContactsInfo.visible"
      :saveEmpty="true"
      :query="selectMaintenanceContactsInfo.query"
      :api="selectMaintenanceContactsInfo.api"
      :check-box="false"
      :highlight-row="true"
      :showPermission="false"
      @callback="selectMaintenanceContactsCallBack"
    />
    <selectMaintenanceUsers
      v-if="selectHospitalMaintainerInfo.visible"
      v-model:showDialog="selectHospitalMaintainerInfo.visible"
      :api="selectMaintenanceContactsInfo.api"
      :saveEmpty="true"
      :query="selectHospitalMaintainerInfo.query"
      :check-box="false"
      :highlight-row="true"
      :showPermission="true"
      @callback="selectHospitalMaintainerCallBack"
    />
    <Select-users
      v-if="selectUseUserInfo.visible"
      v-model:showDialog="selectUseUserInfo.visible"
      :query="selectUseUserInfo.query"
      :api="getRrgUserList"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectUseUserCallBack"
    />

    <Select-users
      v-if="selectResponsibleUserInfo.visible"
      v-model:showDialog="selectResponsibleUserInfo.visible"
      :query="selectResponsibleUserInfo.query"
      :api="getRrgUserList"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectResponsibleUserCallBack"
    />

    <Select-setting-category
      v-if="selectSettingCategoryInfo.visible"
      v-model:showDialog="selectSettingCategoryInfo.visible"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectSettingCategoryInfoCallBack"
    />

    <SelectSettingClassification
      v-if="selectSettingClassificationInfo.visible"
      v-model:showDialog="selectSettingClassificationInfo.visible"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectSettingClassificationInfoCallBack"
    />

    <!-- 资产分类 -->
    <SelectAssetClassify
      v-if="selectAssetClassifyInfo.visible"
      v-model:showDialog="selectAssetClassifyInfo.visible"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectAssetClassifyInfoCallBack"
    />
    <select-depot
      v-if="selectDepotInfo.visible"
      v-model:show-dialog="selectDepotInfo.visible"
      :check-box="false"
      :highlight-row="true"
      :query="selectDepotInfo.query"
      :save-empty="true"
      @callback="selectDepotCallBack"
    />
    <SelectAssetCapitalProject
      v-if="selectAssetCapitalProjectInfo.visible"
      v-model:showDialog="selectAssetCapitalProjectInfo.visible"
      :saveEmpty="true"
      :highlight-row="true"
      :query="selectAssetCapitalProjectInfo.query"
      :checkedRowList="selectAssetCapitalProjectInfo.checkedRowList"
      :capitalProjectData="selectAssetCapitalProjectInfo.capitalProjectData"
      :qty="formInfo.data.canBuildCardCalcQty"
      :assetId="formInfo.data.id"
      @callback="selectAssetCapitalProjectCallBack"
    />
    <!-- 资金来源 -->
    <AssetCapitalSource
      v-if="capitalSourceAdjustInfo.visible"
      v-model:show-dialog="capitalSourceAdjustInfo.visible"
      :data="capitalSourceAdjustInfo.data"
      @callback="capitalSourceAdjustCallback"
    />
    <Amortization
      v-if="addAmortizationInfo.visible"
      v-model:show-dialog="addAmortizationInfo.visible"
      :list="addAmortizationInfo.data"
      @callback="amortizationBack"
    ></Amortization>
  </div>
</template>

<script setup name="BuildAssetCard">
import {
  getUnitAll,
  getSupplierPage,
  getDepotsSelectPageAndMaintenanceGroup,
  getDeptsSelectPageAndMaintenanceGroup,
} from '@/api/core'
import utils from '@/common/js/utils' // 公共方法
import { getRrgUserList } from '@/api/base.js'

import {
  getCategoryDetailsById,
  getAssetStoreOrderDetailCustomizeList,
  batchBuildByAssetStoreOrders,
  batchBuildByReceive,
  getReceiveDetailsAll,
  storeAssetStoreOrder,
  confirmReceive,
} from '@/api/asset.js'
import associatedSubcard from '@/views/asset/assetManage/assetCard/component/associatedSubcard.vue'
import axios from 'axios'
import _ from 'lodash'
import selectMaintenanceUsers from '@/components/SelectUsers/selectMaintenanceUsers'
import moment from 'moment'
import { getCustomizeSetting } from '@/api/customize'
const { proxy } = getCurrentInstance()
const emits = defineEmits()
const props = defineProps([
  'visible',
  'currentAccountingInterval',
  'type',
  'tableRow',
])
let validateDeprMonthsLimit = (rule, value, callback) => {
  if (value === '') {
    callback(new Error('请输入折旧月限'))
  } else {
    if (formInfo.value.data.monthsUsed !== '') {
      if (value < formInfo.value.data.monthsUsed) {
        callback(new Error('输入的折旧月限不能小于已使用月数!'))
      } else {
        callback()
      }
    }
    callback()
  }
}
let validateMonthsUsed = (rule, value, callback) => {
  if (value === '' || value == undefined) {
    callback(new Error('请输入已使用月数'))
  } else if (
    formInfo.value.data.deprMonthsLimit < value &&
    formInfo.value.data.deprMethodType != '0'
  ) {
    callback(new Error('输入的已使用月数不能大于折旧月限!'))
  } else {
    const reg = /^(0|[1-9][0-9]*)$/
    if (!reg.test(value) && formInfo.value.data.deprMethodType != '0') {
      callback(new Error('输入大于等于0的整数'))
    } else {
      callback()
    }
  }
}
let validateResidualAmount = (rule, value, callback) => {
  let originalAmount = formInfo.value.data.originalAmount
    ? formInfo.value.data.originalAmount
    : 0
  if (value === '' || value == undefined) {
    callback(new Error('请输入0~999999999999999的数字'))
  } else if (originalAmount < value) {
    callback(new Error('输入的残值不能大于原值!'))
  } else {
    callback()
  }
}
let validateDeprPreparation = (rule, value, callback) => {
  let originalAmount = formInfo.value.data.originalAmount
    ? formInfo.value.data.originalAmount
    : 0
  if (value === '' || value == undefined) {
    callback()
  } else if (originalAmount < value) {
    callback(new Error('输入的减值准备不能大于原值!'))
  } else {
    callback()
  }
}
let validateSumDeprAmount = (rule, value, callback) => {
  let originalAmount = formInfo.value.data.originalAmount
    ? formInfo.value.data.originalAmount
    : 0
  if (value === '' || value == undefined) {
    callback(new Error('请输入0~999999999999999的数字'))
  } else if (originalAmount < value) {
    callback(new Error('输入的累计折旧不能大于原值!'))
  } else {
    callback()
  }
}
const activeName = ref('0')
const tableInfo = ref({
  data: [],
})
const filterInfo = ref({
  query: {
    customizeUserVO: {},
    queryMap: {
      orderId: {
        queryType: 'IN',
        queryCategory: 'AND',
        value: null,
      },
    },
    queryParams: {},
  },
})

const fullInfo = ref({
  btnList: [
    {
      label: '批量设置资金来源',
      event: batchAssetCapitalSourceVOList,
      show: true,
    },
    {
      label: '批量设置摊销部门',
      event: batchAssetAmortizationDeptVOList,
      show: true,
    },
    { label: '保存', event: save, show: true },
  ],
})
const checkTimePickerOptions = ref({
  disabledDate: (time) => {
    return time.getTime() > Date.now() - 8.64e6
  },
})
const isShowAddEquipment = ref(false)
const productionTimePickerOptions = ref({})
const selectProductSupplier = ref({
  visible: false,
  api: getSupplierPage,
  query: {
    supplierAuth: 'supplierId',
  },
})
const selectMaintenanceProvider = ref({
  visible: false,
  query: {},
})
const selectDepotInfo = ref({
  visible: false,
  query: {
    depotAuth: 'id',
    status: 1,
    useTypeId: 2,
    isCargoSpaceManage: 0,
  },
})
const selectKeeperUserInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {
    hasAllDept: 1,
  },
})
const selectAcceptanceUserInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {
    hasAllDept: 1,
  },
})
const selectPurchUserInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {
    hasAllDept: 1,
  },
})
const selectApplicationUserInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {
    hasAllDept: 1,
  },
})
const selectReceiveUserInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {
    hasAllDept: 1,
  },
})
const selectMaintenanceContactsInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {
    orgId: '',
  },
})
const selectHospitalMaintainerInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {
    orgId: '',
  },
})
const selectUseUserInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {
    hasAllDept: 1,
  },
})
const selectSettingClassificationInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {},
})
const selectSettingCategoryInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {},
})
const selectAssetCapitalProjectInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {},
  checkedRowList: [],
})
const selectResponsibleUserInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {
    hasAllDept: 1,
  },
})
const selectUseDeptInfo = ref({
  visible: false,
  query: {
    deptAuth: 'id',
  },
})
const selectCommonDeptInfo = ref({
  visible: false,
  query: {
    deptAuth: 'id',
  },
})

const selectAssetClassifyInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {},
})
const addAssetAmortizationDeptInfo = ref({
  visible: false,
  query: {
    deptAuth: 'id',
    idNotIn: '',
  },
})
const formInfo = ref({
  baseRef: null,
  commonRef: null,
  financeRef: null,
  maintenanceRef: null,
  measurementRef: null,
  data: {
    // originalAmount: 0,
    // accrualMark: 1,
    // monthsUsed: 0,
    // residualRate: 0,
    // sumDeprAmount: 0,
    // deprMonthsLimit: 0,
    // isFinanceAsset: 0,
    // isMaintenance: 0,
    // isMetering: 0,
    // assetAmortizationDeptVOList: [{ amortizationDeptName: '' }],
    // assetCapitalSourceVOList: [{ code: '', amount: 0 }],
    // qty: 1,
  },
  formDisabled: false,
  delFiledList: [],
  fileType: ['png', 'jpg', 'jpeg', 'pdf'],
  imageField: {
    label: '资产图片',
    value: 'fileUrlList',
    action: axios.defaults.baseURL + '/pub/uploadfile',
    multipleSheets: true,
    listType: 'text',
    limit: 10,
    multiple: false,
    fileType: ['png', 'jpg', 'jpeg', 'gif'],
  },
  fieldUploadList: [
    {
      label: '资产图片',
      value: 'fileUrlList',
      type: 'slot',
      className: 'not-br',
    },
  ],
  baseInfoFieldList: [
    {
      label: '资产名称',
      value: 'assetName',
      type: 'input',
      required: true,
      maxlength: 100,
      disabled: true,
    },
    {
      label: '资产卡片号',
      value: 'assetCode',
      type: 'input',
      show: false,
      required: true,
      disabled: true,
    },
    {
      label: '规格',
      value: 'standard',
      type: 'input',
      maxlength: 100,
    },
    {
      label: '厂家名称',
      value: 'brandName',
      type: 'input',
      maxlength: 100,
    },
    {
      label: '品牌',
      value: 'mark',
      type: 'input',
      maxlength: 100,
    },
    {
      label: '医疗器械分类目录',
      value: 'deviceTypeValue',
      type: 'slot',
    },
    {
      label: '临时采购',
      value: 'temporaryPurch',
      type: 'select-model',
      clearable: true,
      code: 'default_no_or_yes',
      disabled: true,
    },
    {
      label: '供应商',
      value: 'supplierName',
      type: 'slot',
      required: false,
    },
    {
      label: '产地',
      value: 'originPlace',
      type: 'input',
    },

    {
      label: '使用状态',
      value: 'useStatus',
      type: 'select-model',
      code: 'asset_use_status',
      onlyShowOption: ['1', '2'],
      // optionDisabled: ["3", "4", "5", "6", "7", "8", "9", "10", "11"],
      required: true,
      event: 'useStatus',
      disabled: true,
    },
    {
      label: '计提标志',
      value: 'accrualMark',
      type: 'select-model',
      clearable: true,
      code: 'accrual_mark',
      required: true,
      disabled: true,
    },
    {
      label: '使用部门',
      value: 'useDeptName',
      type: 'slot',
      required: true,
      show: false,
    },
    {
      label: '仓库',
      value: 'depotName',
      type: 'slot',
      required: true,
      show: true,
    },
    {
      label: '管理部门',
      value: 'manageDeptName',
      type: 'slot',
      required: true,
    },
    {
      label: '增加方式',
      value: 'increaseType',
      type: 'select-model',
      // clearable: true,
      code: 'increase_type',
      required: true,
    },
    {
      label: '计量单位',
      value: 'unitId',
      type: 'select',
      clearable: true,
      list: 'unitList',
      filterable: true,
      required:
        proxy.$store.state.permission.systemConfig.asset_unit_necessarily == '1'
          ? true
          : false,
    },
    {
      label: '数量',
      value: 'qty',
      type: 'number',
      max: 99999999,
      disabled: true,
      // formatter: proxy.$fn.TripartiteMethodAsset,
    },
    {
      label: '金额',
      value: 'primitiveOriginalAmount',
      type: 'number',
      max: 999999999999999,
      formatter: proxy.$fn.TripartiteMethodAsset,
      precision:
        proxy.$store.state.permission.systemConfig.assets_price_precision,
      required: true,
      disabled: true,
      event: 'primitiveOriginalAmount',
    },
    {
      label: '资产分类',
      value: 'classifyTypeValue',
      type: 'slot',
      required: true,
    },
    {
      label: '资产财务分类',
      value: 'financialClassifyTypeValue',
      type: 'slot',
    },
    {
      label: '设备标识',
      value: 'assetMark',
      type: 'select-model',
      clearable: true,
      multiple: true,
      code: 'assets_mark',
    },

    {
      label: '是否为财务资产',
      value: 'isFinanceAsset',
      type: 'radio-model',
      code: 'yes_or_no',
      // disabled: true,
      // show: proxy.$permission("assetCard:financeAsset"),
    },
    {
      label: '是否维保',
      value: 'isMaintenance',
      type: 'radio-model',
      code: 'yes_or_no',
      // show: proxy.$permission("assetCard:maintenance"),
    },
    {
      label: '是否为计量资产',
      value: 'isMetering',
      type: 'radio-model',
      code: 'yes_or_no',
      // show: proxy.$permission("assetCard:metering"),
    },
    {
      label: '资金来源',
      value: 'assetCapitalSourceVOList',
      type: 'slot',
      className: 'not-br',
      required: true,
    },
    {
      label: '组件/部件',
      value: 'associatedSubcard',
      type: 'slot',
      className: 'not-br',
      labelTip: '必须填了组件名称和数量才算一条有效的组件/部件',
    },
    {
      label: '备注',
      value: 'remark',
      type: 'textarea',
    },
    {
      label: '资产文档',
      value: 'assetFileUrlList',
      type: 'slot',
      className: 'not-br',
    },
  ],
  commonInfoFieldList: [
    {
      label: 'SN',
      value: 'machineCode',
      type: 'input',
      maxlength: 32,
    },
    {
      label: '注册证号',
      value: 'registerCode',
      type: 'input',
      maxlength: 32,
    },
    {
      label: '合同号',
      value: 'contractCode',
      type: 'input',
      maxlength: 32,
    },
    {
      label: '档案号',
      value: 'fileCode',
      type: 'input',
      maxlength: 32,
    },
    {
      label: '发票编号',
      value: 'invoiceCode',
      type: 'input',
      maxlength: 32,
    },
    {
      label: '批号',
      value: 'batchNumber',
      type: 'input',
      maxlength: 32,
    },
    {
      label: '出厂日期',
      value: 'manufactureDate',
      type: 'date',
      placeholder: false,
    },
    {
      label: '生产日期',
      value: 'productionDate',
      type: 'date',
      placeholder: false,
    },
    {
      label: '安装日期',
      value: 'installDate',
      type: 'date',
      placeholder: false,
    },
    // {
    //   label: "启用日期",
    //   value: "enableDate",
    //   type: "date",
    //   placeholder: false,
    // },
    {
      label: '验收人',
      value: 'acceptanceUserName',
      type: 'slot',
    },
    {
      label: '验收日期',
      value: 'acceptanceDate',
      type: 'date',
      placeholder: false,
    },
    {
      label: '采购人',
      value: 'purchUserName',
      type: 'slot',
    },
    {
      label: '采购日期',
      value: 'purchDate',
      type: 'date',
      placeholder: false,
    },
    {
      label: '开始使用日期',
      value: 'useDate',
      type: 'date',
      placeholder: false,
    },
    {
      label: '领用人',
      value: 'applicationUserName',
      type: 'slot',
    },
    {
      label: '领用日期',
      value: 'applicationDate',
      type: 'date',
      placeholder: false,
    },
    {
      label: '保管人',
      value: 'keeperUserName',
      type: 'slot',
    },
    {
      label: '使用人',
      value: 'useUserName',
      type: 'slot',
    },
    {
      label: '责任人',
      value: 'responsibleUserName',
      type: 'slot',
    },

    {
      label: '接收人',
      value: 'receiveUserName',
      type: 'slot',
    },
    {
      label: '存放地点',
      value: 'location',
      type: 'textarea',
      maxlength: 150,
    },
  ],
  financeInfoFieldList: [
    {
      label: '资产类型',
      value: 'assetType',
      type: 'select-model',
      clearable: true,
      code: 'asset_type',
      required: true,
      disabled: true,
    },

    {
      label: '原值',
      value: 'originalAmount',
      type: 'number',
      required: true,
      placeholder: false,
      disabled: true,
      max: 999999999999999,
      formatter: proxy.$fn.TripartiteMethodAsset,
      precision:
        proxy.$store.state.permission.systemConfig.assets_price_precision,
    },
    {
      label: '净值',
      value: 'netAmount',
      type: 'number',
      placeholder: false,
      disabled: true,
      max: 999999999999999,
      formatter: proxy.$fn.TripartiteMethodAsset,
      precision:
        proxy.$store.state.permission.systemConfig.assets_price_precision,
      labelTip: '计算方法： <br/>' + '原值-累计折旧-减值准备',
    },

    {
      label: '折旧月限',
      value: 'deprMonthsLimit',
      type: 'number',
      required: true,
      placeholder: false,
      max: 99999999,
      show: true,
    },
    {
      label: '已使用月数',
      value: 'monthsUsed',
      type: 'number',
      // required: true,
      placeholder: false,
      max: 99999999,
      show: true,
    },
    {
      label: '减值准备',
      value: 'deprPreparation',
      type: 'number',
      placeholder: false,
      formatter: proxy.$fn.TripartiteMethodAsset,
      precision:
        proxy.$store.state.permission.systemConfig.assets_price_precision,
      max: 999999999999999,
      show: true,
    },
    {
      label: '累计折旧',
      value: 'sumDeprAmount',
      type: 'number',
      required: true,
      placeholder: false,
      formatter: proxy.$fn.TripartiteMethodAsset,
      precision:
        proxy.$store.state.permission.systemConfig.assets_price_precision,
      max: 999999999999999,
      show: true,
    },
    {
      label: '折旧方法',
      value: 'deprMethodType',
      type: 'select-model',
      clearable: true,
      code: 'depr_method_type',
      required: true,
      show: true,
    },
    {
      label: '折旧惯例',
      value: 'deprConvention',
      type: 'select-model',
      clearable: true,
      code: 'depr_convention',
      required: true,
      // disabled: true,
      show: true,
    },

    {
      label: '入账日期',
      value: 'postingDate',
      type: 'slot',
      show: true,
    },
    {
      label: '月折旧率(%)',
      value: 'monthDeprRate',
      type: 'number',
      formatter: proxy.$fn.TripartiteMethodAsset,
      disabled: true,
      precision:
        proxy.$store.state.permission.systemConfig.assets_price_precision,
      max: 100,
      labelTip: '平均折旧法 <br/>' + '月折旧率(%)： 1/折旧月限*100<br/>',
      show: true,
    },
    {
      label: '月折旧额',
      value: 'monthDeprAmount',
      type: 'number',
      formatter: proxy.$fn.TripartiteMethodAsset,
      disabled: true,
      precision:
        proxy.$store.state.permission.systemConfig.assets_price_precision,
      max: 999999999999999,
      labelTip: '平均折旧法 <br/>' + '月折旧额： (原值-减值准备)*月折旧率<br/>',
      show: true,
    },
    {
      label: '摊销部门',
      value: 'assetAmortizationDeptVOList',
      type: 'slot',
      className: 'not-br',
    },
  ],
  maintenanceInfoFieldList: [
    {
      label: '保修类型',
      value: 'warrantyType',
      type: 'select-model',
      clearable: true,
      code: 'warranty_type',
    },
    {
      label: '保修状态',
      value: 'warrantyStatus',
      type: 'select-model',
      clearable: true,
      code: 'warranty_status',
    },
    {
      label: '维保商',
      value: 'maintenanceProviderName',
      type: 'slot',
    },
    {
      label: '维保商联系人',
      value: 'maintenanceContactsName',
      type: 'slot',
    },
    {
      label: '维保商联系人电话',
      value: 'maintenancePhone',
      type: 'input',
      maxlength: 32,
    },
    {
      label: '院内维保人',
      value: 'hospitalMaintainerUserName',
      type: 'slot',
    },
    {
      label: '院内维保人电话',
      value: 'hospitalMaintainerPhone',
      type: 'input',
      maxlength: 32,
    },
    {
      label: '维保开始日期',
      value: 'warrantyStartDate',
      type: 'date',
      placeholder: false,
    },
    {
      label: '维保结束日期',
      value: 'warrantyEndDate',
      type: 'date',
      placeholder: false,
    },
    {
      label: '维保合同编号',
      value: 'maintenanceContract',
      type: 'input',
    },
    {
      label: '维保说明',
      value: 'maintenanceDescription',
      type: 'textarea',
      maxlength: 200,
    },
  ],
  measurementInfoFieldList: [
    {
      label: '标准名称',
      value: 'measurementName',
      type: 'input',
    },
    {
      label: '专业分类',
      value: 'professionalClassification',
      type: 'select-model',
      clearable: true,
      code: 'professional_classification',
    },
    {
      label: '是否强检',
      value: 'isMandatoryInspection',
      type: 'select-model',
      clearable: true,
      code: 'yes_or_no',
    },
    {
      label: '拼音码',
      value: 'pinyinCode',
      type: 'input',
    },
    {
      label: '测量范围',
      value: 'measurementRange',
      type: 'input',
    },
    {
      label: '准确度',
      value: 'accuracy',
      type: 'input',
    },
    {
      label: '检定周期(月)',
      value: 'verificationPeriod',
      type: 'number',
      min: 0,
      max: 9999,
    },
    {
      label: '检定类型',
      value: 'verificationType',
      type: 'select-model',
      clearable: true,
      code: 'verification_type',
    },
    {
      label: '检定单位',
      value: 'verificationUnit',
      type: 'input',
    },
    {
      label: '主要参数',
      value: 'mainParameter',
      type: 'input',
    },
    {
      label: '上次检定日期',
      value: 'verificationDate',
      type: 'slot',
      placeholder: false,
    },
    {
      label: '下次检定日期',
      value: 'validityDate',
      type: 'date',
      placeholder: false,
      disabled: true,
      required: true,
    },
    {
      label: '最新检定结果',
      value: 'verificationResult',
      type: 'select-model',
      clearable: true,
      code: 'verification_result',
    },

    {
      label: '检定证书编号',
      value: 'verificationCertificateNumber',
      type: 'input',
    },
  ],
  baseInfoRules: {},
  financeInfoRules: {
    accrualMark: [
      {
        required: true,
        message: '请选择计提标志',
        trigger: 'change',
      },
    ],
    originalAmount: [
      {
        required: true,
        message: '请输入0~999999999999999的数字',
        trigger: 'blur',
      },
      {
        validator: proxy.$validate.positiveAssetMoneyZero,
        trigger: 'blur',
      },
    ],

    deprMonthsLimit: [
      {
        required: true,
        validator: validateDeprMonthsLimit,
        trigger: 'blur',
      },
      {
        validator: proxy.$validate.positiveAssetMoneyZero,
        trigger: 'blur',
      },
    ],
    deprPreparation: [
      {
        validator: validateDeprPreparation,
        trigger: 'blur',
      },
    ],

    monthsUsed: [
      {
        // required: true,
        validator: validateMonthsUsed,
        trigger: 'blur',
      },
    ],
    sumDeprAmount: [
      {
        required: true,
        validator: validateSumDeprAmount,
        trigger: 'blur',
      },
      {
        validator: proxy.$validate.positiveAssetMoneyZero,
        trigger: 'blur',
      },
    ],
    deprMethodType: [
      {
        required: true,
        message: '请选择折旧方法',
        trigger: 'blur',
      },
    ],
    deprConvention: [
      {
        required: true,
        message: '请选择折旧惯例',
        trigger: 'blur',
      },
    ],
    postingDate: [
      {
        required: true,
        message: '请输入入账日期',
        trigger: 'blur',
      },
    ],
  },
  measurementInfoRules: {
    // verificationPeriod: [
    //   {
    //     required: true,
    //     validator: proxy.$validate.naturalnumber,
    //     trigger: 'blur',
    //   },
    // ],
    // verificationDate: [
    //   {
    //     required: true,
    //     message: '请选择检定日期',
    //     trigger: 'change',
    //   },
    // ],
  },
  labelWidth: '130px',
})
const listTypeInfo = ref({
  licenseList: [],
  brandList: [],
  unitList: [],
})

//资金来源表格
const assetCapitalSourceTableInfo = ref({
  data: [],
  summaryFieldList: [
    { value: 'amount', formatter: proxy.$fn.TripartiteMethodAsset },
  ],
  fieldList: [
    {
      label: '项目类型',
      value: 'code',
      type: 'slot',
    },
    {
      label: '金额',
      value: 'amount',
      type: 'slot',
    },
    {
      label: '资金项目',
      value: 'capitalProjectList',
      type: 'slot',
    },
  ],
  handle: {
    fixed: 'right',
    label: '操作',
    width: '100',
    btList: [
      {
        label: '新增行',
        event: addSource,
        show: true,
      },
      {
        label: '删除',
        event: removeSource,
        popconfirmText: '删除后将改变数据,是否继续？',
        show: true,
        ifRender: ifRenderRemoveSource,
      },
    ],
  },
})
//摊销部门表格
const assetAmortizationDeptTableInfo = ref({
  data: [],
  fieldList: [
    {
      label: '摊销部门',
      value: 'amortizationDeptName',
      type: 'slot',
    },
    {
      label: '占比(%)',
      value: 'amortizationRate',
      type: 'slot',
      labelTip: '总值100%',
    },
  ],
  handle: {
    fixed: 'right',
    label: '操作',
    width: '100',
    btList: [
      {
        label: '新增行',
        event: addDept,
        show: true,
      },
      {
        label: '清空',
        event: clearDept,
        popconfirmText: '清空后将改变数据,是否继续？',
        show: true,
        ifRender: ifRenderClearDept,
      },
      {
        label: '删除',
        event: removeDept,
        popconfirmText: '删除后将改变数据,是否继续？',
        show: true,
        ifRender: ifRenderRemoveDept,
      },
    ],
  },
})
//批量设置资金来源项目类型
const capitalSourceAdjustInfo = ref({
  visible: false,
  data: [],
})
const addAmortizationInfo = ref({
  visible: false,
  data: [],
})
const stockManageData = ref([])
const flag = ref(true)
const maintenanceContactsDisabled = ref(true) //维保商联系人是否不可编辑
const addAssetAmortizationDeptIndex = ref(null)
const changeAmountFlag = ref(false)
const changeAmortizationDeptNameFlag = ref(false)
const assetAmortizationDeptTableForm = ref(null)
const assetCapitalSourceTableForm = ref()
const formRefs = ref(null)
const isValidateTab = ref(false) //切换标签页时是否需要先校验表单
const firstLoad = ref(true)
const beforeLeaveData = ref('')
const oldActiveNum = ref('')
const showDialog = computed({
  get() {
    return props.visible
  },
  set(val) {
    // 更新父组件visible
    emits('update:visible', val)
  },
})
watch(
  () => tableInfo.value.data,
  (val) => {
    selectAssetCapitalProjectInfo.value.capitalProjectData = []

    val.forEach((item) => {
      let amount = 0
      if (
        item.assetCapitalSourceVOList &&
        item.assetCapitalSourceVOList.length
      ) {
        item.assetCapitalSourceVOList.forEach((el) => {
          amount = proxy.$fn.accAdd(amount, el.amount || 0)

          if (el.capitalProjectList && el.capitalProjectList.length) {
            let arr = el.capitalProjectList.map((e) => {
              e.useAmountAll = proxy.$fn.accMul(
                e.useAmount,
                item.canBuildCardCalcQty
              )
              e.assetId = item.id
              return e
            })
            selectAssetCapitalProjectInfo.value.capitalProjectData =
              selectAssetCapitalProjectInfo.value.capitalProjectData.concat(arr)
          }
        })
      }
      if (amount !== item.primitiveOriginalAmount) {
        item.amountValidate = true
      } else {
        item.amountValidate = false
      }
    })
  },
  {
    deep: true,
  }
)
watch(
  () => formInfo.value.data.accrualMark,
  (val) => {
    //计提标志

    if (
      formInfo.value.data.isFinanceAsset &&
      !(
        formInfo.value.data.useStatus == 1 &&
        formInfo.value.data.accrualMark == 1
      )
    ) {
      formInfo.value.financeInfoRules.assetAmortizationDeptVOList = [
        {
          required: true,
        },
      ]
    } else {
      formInfo.value.financeInfoRules.assetAmortizationDeptVOList = [
        {
          required: false,
        },
      ]
    }
  }
)
watch(
  () => formInfo.value.data.useStatus,
  (val) => {
    if (Number(val) === 1) {
      //待领用
      showFieldListItem(true, 'depotName')
      showFieldListItem(false, 'useDeptName')

      formInfo.value.baseInfoFieldList.forEach((item) => {
        if (item.value === 'accrualMark') {
          item.disabled = false
        }
      })
    } else if (Number(val) === 2) {
      //正常使用
      showFieldListItem(false, 'depotName')
      showFieldListItem(true, 'useDeptName')

      if (flag.value) {
        formInfo.value.data.accrualMark = 0
      }
      formInfo.value.baseInfoFieldList.forEach((item) => {
        if (item.value === 'accrualMark') {
          item.disabled = true
        }
      })
    }
    if (formInfo.value.data.assetStatus === 3) {
      formInfo.value.baseInfoFieldList.forEach((item) => {
        if (item.value === 'accrualMark') {
          item.disabled = false
        }
      })
    }
    if (
      formInfo.value.data.isFinanceAsset &&
      !(
        formInfo.value.data.useStatus == 1 &&
        formInfo.value.data.accrualMark == 1
      )
    ) {
      formInfo.value.financeInfoRules.assetAmortizationDeptVOList = [
        {
          required: true,
        },
      ]
    } else {
      formInfo.value.financeInfoRules.assetAmortizationDeptVOList = [
        {
          required: false,
        },
      ]
    }
  }
)
watch(
  () => formInfo.value.data.disabledSupplier,
  (val) => {
    if (val) {
      formInfo.value.baseInfoFieldList.forEach((item) => {
        if (item.value === 'temporaryPurch') {
          item.disabled = true
        }
      })
    } else {
      formInfo.value.baseInfoFieldList.forEach((item) => {
        if (item.value === 'temporaryPurch') {
          item.disabled = false
        }
      })
    }
  }
)
watch(
  () => formInfo.value.data.temporaryPurch,
  (val) => {
    if (flag.value) {
      if (val == 1) {
        formInfo.value.data.supplierName = ''
        formInfo.value.data.supplierId = -2
      }
    }
  }
)
watch(
  //初始原值
  () => formInfo.value.data.primitiveOriginalAmount,
  (value) => {
    formInfo.value.data.originalAmount = value
    formInfo.value.data.netAmount = utils.Subtr(
      utils.Subtr(
        utils.Subtr(
          formInfo.value.data.originalAmount || 0,
          formInfo.value.data.residualAmount || 0
        ),
        formInfo.value.data.sumDeprAmount || 0
      ),
      formInfo.value.data.deprPreparation || 0
    )
  }
)

watch(
  //原值
  () => formInfo.value.data.originalAmount,
  (value) => {
    if (flag.value) {
      let residualRate = formInfo.value.data.residualRate
        ? formInfo.value.data.residualRate
        : 0
      if (residualRate) {
        formInfo.value.data.residualAmount =
          utils.accMul(formInfo.value.data.residualRate, value) / 100
      }
      let residualAmount = formInfo.value.data.residualAmount
        ? formInfo.value.data.residualAmount
        : 0
      let sumDeprAmount = formInfo.value.data.sumDeprAmount
        ? formInfo.value.data.sumDeprAmount
        : 0
      let deprPreparation = formInfo.value.data.deprPreparation
        ? formInfo.value.data.deprPreparation
        : 0
      let netAmount = utils.Subtr(
        utils.Subtr(
          utils.Subtr(value || 0, residualAmount || 0),
          sumDeprAmount || 0
        ),
        deprPreparation || 0
      )
      formInfo.value.data.netAmount = netAmount
      changeMouthDepr()
    }
  }
)

watch(
  //折旧方法
  () => formInfo.value.data.deprMethodType,
  (value) => {
    if (flag.value) {
      changeMouthDepr()
    }
    if (value == '0') {
      //如果不折旧，那么隐藏所有跟折旧有关的值，并置为0
      showFinanceFieldListItem(false, 'deprMonthsLimit')
      showFinanceFieldListItem(false, 'deprPreparation')
      showFinanceFieldListItem(false, 'sumDeprAmount')
      showFinanceFieldListItem(false, 'deprConvention')
      showFinanceFieldListItem(false, 'monthDeprRate')
      showFinanceFieldListItem(false, 'monthDeprAmount')

      formInfo.value.data.deprPreparation = 0
      formInfo.value.data.deprMonthsLimit = 0
      formInfo.value.data.sumDeprAmount = 0
      formInfo.value.data.deprConvention = 0
    } else {
      showFinanceFieldListItem(true, 'deprMonthsLimit')
      showFinanceFieldListItem(true, 'deprPreparation')
      showFinanceFieldListItem(true, 'sumDeprAmount')
      showFinanceFieldListItem(true, 'deprConvention')
      showFinanceFieldListItem(true, 'monthDeprRate')
      showFinanceFieldListItem(true, 'monthDeprAmount')
    }
  }
)
watch(
  //减值准备
  () => formInfo.value.data.deprPreparation,
  (value) => {
    if (flag.value) {
      let originalAmount = formInfo.value.data.originalAmount
        ? formInfo.value.data.originalAmount
        : 0
      let sumDeprAmount = formInfo.value.data.sumDeprAmount
        ? formInfo.value.data.sumDeprAmount
        : 0
      let residualAmount = formInfo.value.data.residualAmount
        ? formInfo.value.data.residualAmount
        : 0
      let netAmount = utils.Subtr(
        utils.Subtr(
          utils.Subtr(originalAmount || 0, residualAmount || 0),
          sumDeprAmount || 0
        ),
        value || 0
      )
      formInfo.value.data.netAmount = netAmount
      changeMouthDepr()
    }
  }
)
watch(
  //累计折旧
  () => formInfo.value.data.sumDeprAmount,
  () => {
    if (flag.value) {
      let originalAmount = formInfo.value.data.originalAmount
        ? formInfo.value.data.originalAmount
        : 0
      let sumDeprAmount = formInfo.value.data.sumDeprAmount
        ? formInfo.value.data.sumDeprAmount
        : 0
      let residualAmount = formInfo.value.data.residualAmount
        ? formInfo.value.data.residualAmount
        : 0
      let deprPreparation = formInfo.value.data.deprPreparation
        ? formInfo.value.data.deprPreparation
        : 0
      let netAmount = utils.Subtr(
        utils.Subtr(
          utils.Subtr(originalAmount || 0, residualAmount || 0),
          sumDeprAmount || 0
        ),
        deprPreparation || 0
      )
      formInfo.value.data.netAmount = netAmount
    }
  }
)

watch(
  //折旧月限
  () => formInfo.value.data.deprMonthsLimit,
  () => {
    if (flag.value) {
      changeMouthDepr()
    }
  }
)

watch(
  //是否财务资产
  () => formInfo.value.data.isFinanceAsset,
  (val) => {
    if (val) {
      if (flag.value) {
        formInfo.value.data.originalAmount =
          formInfo.value.data.primitiveOriginalAmount
        if (formInfo.value.data.financialClassifyType > 0 && !firstLoad.value) {
          getDepreciation(formInfo.value.data.financialClassifyType)
        }
        if (
          formInfo.value.data.assetAmortizationDeptVOList &&
          formInfo.value.data.assetAmortizationDeptVOList.length &&
          !changeAmortizationDeptNameFlag.value &&
          Number(formInfo.value.data.useStatus) === 2
        ) {
          formInfo.value.data.assetAmortizationDeptVOList[
            formInfo.value.data.assetAmortizationDeptVOList.length - 1
          ].amortizationDeptName = formInfo.value.data.useDeptName

          formInfo.value.data.assetAmortizationDeptVOList[
            formInfo.value.data.assetAmortizationDeptVOList.length - 1
          ].amortizationDeptId = formInfo.value.data.useDeptId

          formInfo.value.data.assetAmortizationDeptVOList[
            formInfo.value.data.assetAmortizationDeptVOList.length - 1
          ].amortizationRate = 100
        }
        formInfo.value.data.netAmount = utils.Subtr(
          utils.Subtr(
            utils.Subtr(
              formInfo.value.data.originalAmount || 0,
              formInfo.value.data.residualAmount || 0
            ),
            formInfo.value.data.sumDeprAmount || 0
          ),
          formInfo.value.data.deprPreparation || 0
        )
      }

      formInfo.value.baseInfoRules.financialClassifyTypeValue = [
        {
          required: true,
          message: '请选择资产财务分类',
          trigger: 'blur',
        },
      ]
    } else {
      formInfo.value.baseInfoRules.financialClassifyTypeValue = [
        {
          required: false,
          message: '请选择资产财务分类',
          trigger: 'blur',
        },
      ]
    }
    if (
      val &&
      !(
        formInfo.value.data.useStatus == 1 &&
        formInfo.value.data.accrualMark == 1
      )
    ) {
      formInfo.value.financeInfoRules.assetAmortizationDeptVOList = [
        {
          required: true,
        },
      ]
    } else {
      formInfo.value.financeInfoRules.assetAmortizationDeptVOList = [
        {
          required: false,
        },
      ]
    }
  },
  {
    deep: true,
  }
)

watch(
  //是否计量资产
  () => formInfo.value.data.isMetering,
  (val) => {
    if (val) {
      let measurementNameRule = [
        {
          required: true,
          message: '请输入标准名称',
          trigger: 'blur',
        },
      ]
      formInfo.value.measurementInfoRules.measurementName = measurementNameRule
      formInfo.value.data.measurementName = formInfo.value.data.assetName
    } else {
      let measurementNameRule = [
        {
          required: false,
          message: '请输入标准名称',
          trigger: 'blur',
        },
      ]
      formInfo.value.measurementInfoRules.measurementName = measurementNameRule
    }
  },
  {
    deep: true,
  }
)
watch(
  //维保商
  () => formInfo.value.data.maintenanceProviderName,
  (val) => {
    if (val) {
      maintenanceContactsDisabled.value = false
      selectMaintenanceContactsInfo.value.query.orgId =
        formInfo.value.data.maintenanceProvider
    } else {
      maintenanceContactsDisabled.value = true
      selectMaintenanceContactsInfo.value.query.orgId = ''
    }
  }
)
watch(
  //监听一个必有的字段，确保初始化之后flag为true
  () => formInfo.value.data.assetName,
  () => {
    proxy.$nextTick(() => {
      flag.value = true
    })
  }
)
watch(
  //计量资产的失效日期=检定周期+上次检定时间
  () => formInfo.value.data.verificationPeriod,
  (val) => {
    if (val != null && formInfo.value.data.verificationDate) {
      let date1 = new Date(formInfo.value.data.verificationDate)
      date1.setMonth(date1.getMonth() + formInfo.value.data.verificationPeriod)
      let month =
        date1.getMonth() + 1 > 9
          ? date1.getMonth() + 1
          : 0 + '' + (date1.getMonth() + 1)
      let date =
        date1.getDate() > 9 ? date1.getDate() : 0 + '' + date1.getDate()
      formInfo.value.data.validityDate =
        date1.getFullYear() + '-' + month + '-' + date
    }
  }
)
watch(
  () => formInfo.value.data.verificationDate,
  (val) => {
    if (val != null && formInfo.value.data.verificationPeriod) {
      let date1 = new Date(formInfo.value.data.verificationDate)
      date1.setMonth(date1.getMonth() + formInfo.value.data.verificationPeriod)
      let month =
        date1.getMonth() + 1 > 9
          ? date1.getMonth() + 1
          : 0 + '' + (date1.getMonth() + 1)
      let date =
        date1.getDate() > 9 ? date1.getDate() : 0 + '' + date1.getDate()
      formInfo.value.data.validityDate =
        date1.getFullYear() + '-' + month + '-' + date
    }
  }
)

onMounted(() => {
  initRules()
  getUnitList()
  getCustomize()
  productionTimePickerOptions.value = {
    disabledDate(time) {
      if (props.currentAccountingInterval) {
        return (
          time.getTime() <
          new Date(props.currentAccountingInterval).getTime() -
            24 * 60 * 60 * 1000
        )
      }
    },
  }
})
function amortizationBack(data, _changeAmortizationDeptNameFlag) {
  if (data) {
    changeAmortizationDeptNameFlag.value = _changeAmortizationDeptNameFlag
    addAmortizationInfo.value.data = proxy.$fn.deepClone(data)
    tableInfo.value.data.forEach((item) => {
      if (item.isFinanceAsset == 1) {
        item.assetAmortizationDeptVOList = proxy.$fn.deepClone(data)
      }
    })
  }
}
function batchAssetAmortizationDeptVOList() {
  addAmortizationInfo.value.visible = true
}
function capitalSourceAdjustCallback(data) {
  if (data) {
    capitalSourceAdjustInfo.value.data = proxy.$fn.deepClone(data)
    tableInfo.value.data.forEach((item) => {
      item.assetCapitalSourceVOList = proxy.$fn.deepClone(data)
    })
  }
}
function batchAssetCapitalSourceVOList() {
  capitalSourceAdjustInfo.value.visible = true
}
function openAssetCapitalProjectList(index) {
  //打开资金项目弹窗
  selectAssetCapitalProjectInfo.value.index = index
  let assetCapitalSourceVOListElement =
    formInfo.value.data.assetCapitalSourceVOList[index]
  if (
    assetCapitalSourceVOListElement.capitalProjectList &&
    assetCapitalSourceVOListElement.capitalProjectList.length
  ) {
    selectAssetCapitalProjectInfo.value.checkedRowList =
      assetCapitalSourceVOListElement.capitalProjectList
  } else {
    selectAssetCapitalProjectInfo.value.checkedRowList = []
  }
  // selectAssetCapitalProjectInfo.value.query['assetCapitalSourceDictId'] = {
  //   queryType: 'EQUALS',
  //   value: assetCapitalSourceVOListElement.code,
  // }
  if (props.id) {
    selectAssetCapitalProjectInfo.value.queryParams.assetId = props.id
  }
  selectAssetCapitalProjectInfo.value.visible = true
}
function selectAssetCapitalProjectCallBack(data, arr) {
  //资金项目
  if (data && data.length) {
    let capitalProjectName = data.map((item) => item.name).toString()
    formInfo.value.data.assetCapitalSourceVOList[
      selectAssetCapitalProjectInfo.value.index
    ].capitalProjectName = capitalProjectName

    formInfo.value.data.assetCapitalSourceVOList[
      selectAssetCapitalProjectInfo.value.index
    ].capitalProjectList = data.map((item) => {
      return {
        assetCapitalProjectId: item.id,
        useAmount: item.useAmount,
      }
    })

    formInfo.value.data.assetCapitalSourceVOList[
      selectAssetCapitalProjectInfo.value.index
    ].capitalProjectList.forEach((item) => {
      arr.forEach((el) => {
        if (el.id === item.id) {
          item.useAmount = el.useAmount
        }
      })
    })
  } else {
    formInfo.value.data.assetCapitalSourceVOList[
      selectAssetCapitalProjectInfo.value.index
    ].capitalProjectName = ''

    formInfo.value.data.assetCapitalSourceVOList[
      selectAssetCapitalProjectInfo.value.index
    ].capitalProjectList = []
  }
}
function changeCapitalSource(val, index) {
  formInfo.value.data.assetCapitalSourceVOList[index].capitalProjectList = []
}
function changeValidate(value, str, ref) {
  // proxy.$nextTick(() => {
  //   proxy.$refs[ref].clearValidate(str)
  // })
}

function handleEventBaseForm(event) {
  if (event === 'useStatus') {
    formInfo.value.data.depotId = -2
    formInfo.value.data.depotName = ''
    formInfo.value.data.useDeptId = -2
    formInfo.value.data.useDeptName = ''
  } else if (event === 'primitiveOriginalAmount') {
    if (
      !changeAmountFlag.value &&
      formInfo.value.data.assetCapitalSourceVOList &&
      formInfo.value.data.assetCapitalSourceVOList.length === 1
    ) {
      formInfo.value.data.assetCapitalSourceVOList[
        formInfo.value.data.assetCapitalSourceVOList.length - 1
      ].amount = formInfo.value.data.primitiveOriginalAmount
    }
  }
}
function openDepotWindow() {
  selectDepotInfo.value.visible = true
}
function selectDepotCallBack(row) {
  if (row && row.id) {
    formInfo.value.data.depotId = row.id
    formInfo.value.data.depotName = row.name
  } else {
    formInfo.value.data.depotId = -2
    formInfo.value.data.depotName = ''
  }
}

function handleResponse(response, file) {
  return file
}
function openAmortizationDept(index) {
  //新增摊销部门
  let ids = []
  if (
    formInfo.value.data.assetAmortizationDeptVOList &&
    formInfo.value.data.assetAmortizationDeptVOList.length
  ) {
    formInfo.value.data.assetAmortizationDeptVOList.forEach((item) => {
      if (item.amortizationDeptName) {
        ids.push(item.amortizationDeptId)
      }
    })
  }
  addAssetAmortizationDeptInfo.value.query.idNotIn = String(ids)
  addAssetAmortizationDeptIndex.value = index
  addAssetAmortizationDeptInfo.value.visible = true
}
function addDept() {
  formInfo.value.data.assetAmortizationDeptVOList.push({
    amortizationDeptName: '',
  })
}
function selectAssetAmortizationDeptCallback(data) {
  changeAmortizationDeptNameFlag.value = true
  if (data) {
    formInfo.value.data.assetAmortizationDeptVOList.forEach((item, index) => {
      if (index === addAssetAmortizationDeptIndex.value) {
        item.amortizationDeptName = data.name
        item.amortizationDeptId = data.id
      }
    })
  } else {
    formInfo.value.data.assetAmortizationDeptVOList.forEach((item, index) => {
      activeName
      if (index === addAssetAmortizationDeptIndex.value) {
        item.amortizationDeptName = ''
        ;(item = 'amortizationDeptId'), -2
      }
    })
  }
  addAssetAmortizationDeptInfo.value.visible = false
}
function removeDept(row) {
  //删除摊销部门
  formInfo.value.data.assetAmortizationDeptVOList =
    formInfo.value.data.assetAmortizationDeptVOList.filter(
      (item) => item !== row
    )
  setTimeout(() => {
    if (assetAmortizationDeptTableForm.value[Number(activeName.value)]) {
      assetAmortizationDeptTableForm.value[
        Number(activeName.value)
      ].clearValidate()
    }
  }, 30)
}
function ifRenderRemoveDept() {
  if (formInfo.value.data.assetAmortizationDeptVOList.length - 1) {
    return true
  } else {
    return false
  }
}
function clearDept() {
  //清空摊销部门
  formInfo.value.data.assetAmortizationDeptVOList = [
    { amortizationDeptName: '' },
  ]
}
function ifRenderClearDept() {
  if (formInfo.value.data.assetAmortizationDeptVOList.length === 1) {
    return true
  } else {
    return false
  }
}
function ifRenderRemoveSource() {
  if (formInfo.value.data.assetCapitalSourceVOList.length - 1) {
    return true
  } else {
    return false
  }
}
function addSource() {
  //增加资金来源
  formInfo.value.data.assetCapitalSourceVOList.push({
    code: '',
    amount: 0,
  })
}
function removeSource(row) {
  //删除资金来源
  formInfo.value.data.assetCapitalSourceVOList =
    formInfo.value.data.assetCapitalSourceVOList.filter((item) => item !== row)
}
function getDepreciation(id) {
  if (id && id !== -2) {
    getCategoryDetailsById(id).then((res) => {
      if (res && res.success) {
        let row = res.data
        formInfo.value.data.deprConvention = row.deprConvention

        formInfo.value.data.deprConventionValue = row.deprConventionValue

        formInfo.value.data.deprMethodType = row.deprMethodType

        formInfo.value.data.deprMethodTypeValue = row.deprMethodTypeValue

        formInfo.value.data.deprMonthsLimit = row.deprMonthsLimit
      }
    })
  } else {
    formInfo.value.data.deprConvention = -2

    formInfo.value.data.deprConventionValue = ''

    formInfo.value.data.deprMethodType = -2

    formInfo.value.data.deprMethodTypeValue = ''

    formInfo.value.data.deprMonthsLimit = 0
  }
}

// 初始化校验规则
function initRules() {
  formInfo.value.baseInfoRules = proxy.$initRules(
    formInfo.value.baseInfoFieldList
  )
  formInfo.value.commonRules = proxy.$initRules(
    formInfo.value.commonInfoFieldList
  )
  formInfo.value.maintenanceInfoRules = proxy.$initRules(
    formInfo.value.maintenanceInfoFieldList
  )
  formInfo.value.maintenanceInfoRules.maintenancePhone = [
    { validator: proxy.$validate.cellphone, trigger: 'blur' },
  ]
}
//获取计量单位列表
function getUnitList() {
  getUnitAll().then((resp) => {
    if (resp && resp.success && resp.data && resp.data.length > 0) {
      listTypeInfo.value.unitList = resp.data.map(function (item) {
        return { key: item.name, value: item.id }
      })
    }
  })
}
function handleEvent(e) {}

function changeMouthDepr() {
  let value = formInfo.value.data.deprMethodType

  let deprMonthsLimit = formInfo.value.data.deprMonthsLimit
    ? formInfo.value.data.deprMonthsLimit
    : 0
  let originalAmount = formInfo.value.data.originalAmount
    ? formInfo.value.data.originalAmount
    : 0
  let deprPreparation = formInfo.value.data.deprPreparation
    ? formInfo.value.data.deprPreparation
    : 0

  if (value == '0') {
    //不折旧
    formInfo.value.data.monthDeprRate = 0
    formInfo.value.data.monthDeprAmount = 0
  } else if (value == '1') {
    //平均折旧法
    let residualRate = 0
    if (deprMonthsLimit) {
      let monthDeprRate = utils.accDiv(
        utils.Subtr(1, residualRate),
        deprMonthsLimit
      )
      let monthDeprAmount

      monthDeprAmount = utils.accMul(
        utils.Subtr(originalAmount || 0, deprPreparation || 0),
        utils.getAssetRate(monthDeprRate)
      )

      formInfo.value.data.monthDeprRate = monthDeprRate * 100
      formInfo.value.data.monthDeprAmount = monthDeprAmount
    } else {
      formInfo.value.data.monthDeprRate = 0
      formInfo.value.data.monthDeprAmount = 0
    }
  }
}
function openAssetClassifyWindow() {
  selectAssetClassifyInfo.value.visible = true
}
function openUseDeptWindow() {
  if (!formInfo.value.data.useDeptName) {
    selectUseDeptInfo.value.visible = true
  }
}
function openManageDeptWindow() {
  selectCommonDeptInfo.value.visible = true
}

function openSupplierWindow() {
  selectProductSupplier.value.visible = true
}
function openMaintenanceProviderWindow() {
  selectMaintenanceProvider.value.visible = true
}

function openKeeperUserList() {
  selectKeeperUserInfo.value.visible = true
}
function openAcceptanceUserList() {
  selectAcceptanceUserInfo.value.visible = true
}
function openPurchUserList() {
  selectPurchUserInfo.value.visible = true
}
function openApplicationUserList() {
  selectApplicationUserInfo.value.visible = true
}
function openReceiveUserList() {
  selectReceiveUserInfo.value.visible = true
}
function openMaintenanceContactsList() {
  if (!maintenanceContactsDisabled.value) {
    selectMaintenanceContactsInfo.value.visible = true
  }
}
function openHospitalMaintainerUserList() {
  selectHospitalMaintainerInfo.value.visible = true
}
function openUseUserList() {
  selectUseUserInfo.value.visible = true
}
function openResponsibleUserList() {
  selectResponsibleUserInfo.value.visible = true
}
function openFinanceTypeWindow() {
  selectSettingCategoryInfo.value.visible = true
}
function openDeviceTypeWindow() {
  selectSettingClassificationInfo.value.visible = true
}

function selectUseDeptCallback(row) {
  if (row) {
    formInfo.value.data.useDeptId = row.id
    formInfo.value.data.useDeptName = row.name
  } else {
    formInfo.value.data.useDeptId = '.'
    formInfo.value.data.useDeptName = ''
  }

  if (
    formInfo.value.data.assetAmortizationDeptVOList.length &&
    !changeAmortizationDeptNameFlag.value
  ) {
    formInfo.value.data.assetAmortizationDeptVOList[
      formInfo.value.data.assetAmortizationDeptVOList.length - 1
    ].amortizationDeptName = formInfo.value.data.useDeptName

    formInfo.value.data.assetAmortizationDeptVOList[
      formInfo.value.data.assetAmortizationDeptVOList.length - 1
    ].amortizationDeptId = formInfo.value.data.useDeptId

    formInfo.value.data.assetAmortizationDeptVOList[
      formInfo.value.data.assetAmortizationDeptVOList.length - 1
    ].amortizationRate = 100
  }
}
function selectCommonDeptCallback(row) {
  if (row) {
    formInfo.value.data.manageDeptId = row.id
    formInfo.value.data.manageDeptName = row.name
  } else {
    formInfo.value.data.manageDeptId = ''
    formInfo.value.data.manageDeptName = ''
  }
}

function selectSupplierCallback(row) {
  if (row) {
    formInfo.value.data.supplierId = row.supplierId
    formInfo.value.data.supplierName = row.supplierName
  } else {
    formInfo.value.data.supplierId = ''
    formInfo.value.data.supplierName = ''
  }
}
function selectMaintenanceProviderCallback(row) {
  if (row) {
    formInfo.value.data.maintenanceProvider = row.maintenanceId

    formInfo.value.data.maintenanceProviderName = row.maintenanceName

    formInfo.value.data.maintenanceContacts = ''
    formInfo.value.data.maintenanceContactsName = ''
  } else {
    formInfo.value.data.maintenanceProvider = ''
    formInfo.value.data.maintenanceProviderName = ''
  }
}

function selectKeeperUserCallBack(row) {
  if (row) {
    formInfo.value.data.keeperUser = row.id
    formInfo.value.data.keeperUserName = row.name
  } else {
    formInfo.value.data.keeperUser = ''
    formInfo.value.data.keeperUserName = ''
  }
}
function selectAcceptanceUserCallBack(row) {
  if (row) {
    formInfo.value.data.acceptanceUser = row.id
    formInfo.value.data.acceptanceUserName = row.name
  } else {
    formInfo.value.data.acceptanceUser = ''
    formInfo.value.data.acceptanceUserName = ''
  }
}
function selectPurchUserCallBack(row) {
  if (row) {
    formInfo.value.data.purchUser = row.id
    formInfo.value.data.purchUserName = row.name
  } else {
    formInfo.value.data.purchUser = ''
    formInfo.value.data.purchUserName = ''
  }
}
function selectApplicationUserCallBack(row) {
  if (row) {
    formInfo.value.data.applicationUser = row.id
    formInfo.value.data.applicationUserName = row.name
  } else {
    formInfo.value.data.applicationUser = ''
    formInfo.value.data.applicationUserName = ''
  }
}
function selectReceiveUserCallBack(row) {
  if (row) {
    formInfo.value.data.receiveUser = row.id
    formInfo.value.data.receiveUserName = row.name
  } else {
    formInfo.value.data.receiveUser = ''
    formInfo.value.data.receiveUserName = ''
  }
}
function selectMaintenanceContactsCallBack(row) {
  if (row) {
    formInfo.value.data.maintenanceContacts = row.userId
    formInfo.value.data.maintenanceContactsName = row.name
    formInfo.value.data.maintenancePhone = row.tel
  } else {
    formInfo.value.data.maintenanceContacts = ''
    formInfo.value.data.maintenanceContactsName = ''
    formInfo.value.data.maintenancePhone = ''
  }
}
function selectHospitalMaintainerCallBack(row) {
  if (row) {
    formInfo.value.data.hospitalMaintainerUser = row.userId
    formInfo.value.data.hospitalMaintainerUserName = row.name
    formInfo.value.data.hospitalMaintainerPhone = row.tel
  } else {
    formInfo.value.data.hospitalMaintainerUser = ''
    formInfo.value.data.hospitalMaintainerUserName = ''
    formInfo.value.data.hospitalMaintainerPhone = ''
  }
}
function selectUseUserCallBack(row) {
  if (row) {
    formInfo.value.data.useUser = row.id
    formInfo.value.data.useUserName = row.name
  } else {
    formInfo.value.data.useUser = ''
    formInfo.value.data.useUserName = ''
  }
}
function selectResponsibleUserCallBack(row) {
  if (row) {
    formInfo.value.data.responsibleUser = row.id
    formInfo.value.data.responsibleUserName = row.name
  } else {
    formInfo.value.data.responsibleUser = ''
    formInfo.value.data.responsibleUserName = ''
  }
}
function selectSettingCategoryInfoCallBack(row) {
  if (row) {
    formInfo.value.data.financialClassifyType = row.id
    formInfo.value.data.financialClassifyTypeValue = row.name
    formInfo.value.data.isFinanceAsset = 1
    formInfo.value.data.deprConvention = row.deprConvention

    formInfo.value.data.deprConventionValue = row.deprConventionValue

    formInfo.value.data.deprMethodType = row.deprMethodType

    formInfo.value.data.deprMethodTypeValue = row.deprMethodTypeValue

    formInfo.value.data.deprMonthsLimit = row.deprMonthsLimit
    firstLoad.value = false
  } else {
    formInfo.value.data.financialClassifyType = ''
    formInfo.value.data.financialClassifyTypeValue = ''
    formInfo.value.data.isFinanceAsset = 0
    formInfo.value.data.deprConvention = ''
    formInfo.value.data.deprConventionValue = ''
    formInfo.value.data.deprMethodType = ''
    formInfo.value.data.deprMethodTypeValue = ''
    formInfo.value.data.deprMonthsLimit = ''
  }
}
function selectAssetClassifyInfoCallBack(row) {
  if (row) {
    formInfo.value.data.classifyType = row.id
    formInfo.value.data.classifyTypeValue = row.name

    formInfo.value.data.financialClassifyType = row.assetFinancialClassifyId

    formInfo.value.data.financialClassifyTypeValue =
      row.assetFinancialClassifyName

    formInfo.value.data.assetType = row.assetType
    formInfo.value.data.assetTypeValue = row.assetTypeValue
    getDepreciation(row.assetFinancialClassifyId)
  } else {
    formInfo.value.data.classifyType = '-2'
    formInfo.value.data.classifyTypeValue = ''
    formInfo.value.data.financialClassifyType = '-2'
    formInfo.value.data.financialClassifyTypeValue = ''
    formInfo.value.data.deprConvention = ''
    formInfo.value.data.deprConventionValue = ''
    formInfo.value.data.deprMethodType = ''
    formInfo.value.data.deprMethodTypeValue = ''
    formInfo.value.data.deprMonthsLimit = ''
    formInfo.value.data.assetType = ''
    formInfo.value.data.assetTypeValue = ''
  }
}
function selectSettingClassificationInfoCallBack(row) {
  if (row) {
    formInfo.value.data.deviceType = row.id
    formInfo.value.data.deviceTypeValue = row.name
  } else {
    formInfo.value.data.deviceType = ''
    formInfo.value.data.deviceTypeValue = ''
  }
}

function validiteFun(str = undefined, _activeName) {
  //必填校验+其他校验
  let _formRefs = []
  formRefs.value = []

  _formRefs.push(formInfo.value['baseRef' + Number(activeName.value)])
  _formRefs.push(formInfo.value['commonRef' + Number(activeName.value)])
  if (
    tableInfo.value.data[Number(activeName.value)].isFinanceAsset &&
    formInfo.value['financeRef' + Number(activeName.value)]
  ) {
    _formRefs.push(formInfo.value['financeRef' + Number(activeName.value)])
  }
  if (formInfo.value['maintenanceRef' + Number(activeName.value)]) {
    _formRefs.push(formInfo.value['maintenanceRef' + Number(activeName.value)])
  }
  if (formInfo.value['measurementRef' + Number(activeName.value)]) {
    _formRefs.push(formInfo.value['measurementRef' + Number(activeName.value)])
  }
  if (proxy.$refs['assetCapitalSourceTableForm' + Number(activeName.value)]) {
    _formRefs.push(
      proxy.$refs['assetCapitalSourceTableForm' + Number(activeName.value)][0]
    )
  }
  // if (
  //   tableInfo.value.data[Number(activeName.value)].isFinanceAsset &&
  //   proxy.$refs['assetAmortizationDeptTableForm' + Number(activeName.value)] &&
  //   !(
  //     tableInfo.value.data[Number(activeName.value)].useStatus == 1 &&
  //     tableInfo.value.data[Number(activeName.value)].accrualMark == 1
  //   )
  // ) {
  //   //摊销部门的校验
  //   _formRefs.push(
  //     proxy.$refs[
  //       'assetAmortizationDeptTableForm' + Number(activeName.value)
  //     ][0]
  //   )
  // }//不生效，先注释

  formRefs.value = _formRefs
  proxy.$fn
    .checkForm(formRefs.value)
    .then(() => {
      //  let tableData = proxy.$fn.deepClone(tableInfo.value.data)
      if (formInfo.value.data.assetCapitalSourceVOList.length) {
        //资金来源：一份资产卡片只能拥有一行相同的项目类型
        let warning = false
        formInfo.value.data.assetCapitalSourceVOList.some((e, index, arr) => {
          if (
            arr.filter((e1) => Number(e1.code) == Number(e.code)).length > 1
          ) {
            warning = true
          }
        })
        if (warning) {
          proxy.$message.warning('一份资产卡片只能拥有一行相同的项目类型')
          return
        }
        let primitiveOriginalAmount = 0
        formInfo.value.data.assetCapitalSourceVOList.forEach((item) => {
          primitiveOriginalAmount = proxy.$fn.accAdd(
            item.amount || 0,
            primitiveOriginalAmount
          )
        })
        if (
          primitiveOriginalAmount !==
          formInfo.value.data.primitiveOriginalAmount
        ) {
          proxy.$message.warning('当前资产的资金来源金额合计要与金额相等！')
          return
        }
        let _warning = false
        let _warningIndex = []
        formInfo.value.data.assetCapitalSourceVOList.forEach((item, index) => {
          let useAmount = 0
          if (item.capitalProjectList && item.capitalProjectList.length) {
            item.capitalProjectList.forEach((el) => {
              useAmount = proxy.$fn.accAdd(el.useAmount || 0, useAmount)
            })
            if (useAmount > item.amount) {
              _warning = true
              _warningIndex.push(index + 1)
            }
          }
        })
        if (_warning) {
          proxy.$message.warning(
            `当前资产的【第${String(
              _warningIndex
            )}行】的资金项目使用金额之和不能大于资金来源金额！`
          )
          return
        }
      }
      if (
        formInfo.value.data.assetAmortizationDeptVOList.length > 0 &&
        formInfo.value.data.isFinanceAsset
      ) {
        //摊销部门

        let amortizationRate = 0
        let assetAmortizationDeptVOList =
          formInfo.value.data.assetAmortizationDeptVOList.filter((item) => {
            amortizationRate = proxy.$fn.accAdd(
              amortizationRate,
              item.amortizationRate || 0
            )
            return !!item.amortizationDeptName
          })
        if (
          !(
            formInfo.value.data.useStatus == 1 &&
            formInfo.value.data.accrualMark == 1
          )
        ) {
          //摊销部门的校验
          if (!assetAmortizationDeptVOList.length) {
            proxy.$message.warning('请选择当前资产的摊销部门!')
            return
          }
        }
        if (amortizationRate !== 100 && assetAmortizationDeptVOList.length) {
          proxy.$message.warning('当前资产的摊销部门的占比总值必须为100%!')
          return
        }
        if (
          formInfo.value.data.deprMonthsLimit ===
            formInfo.value.data.monthsUsed &&
          formInfo.value.data.netAmount !== 0 &&
          formInfo.value.data.deprMethodType != '0'
        ) {
          proxy.$message({
            type: 'warning',
            duration: 3500,
            message: '当前资产的折旧月限和已使用月数相同，净值必须为0',
            showClose: true,
          })
          return
        }
      }

      formInfo.value.data.isValidate = true
      if (str === 'save') {
        save()
      } else if (str === 'changeTab') {
        activeName.value = _activeName
        let e = {
          paneName: _activeName,
        }
        handleClick(e)
      }
    })
    .catch(() => {
      proxy.$message({
        message: '当前资产必填或非法校验未通过，请检查！',
        type: 'warning',
        duration: 3500,
        showClose: true,
      })
    })
}
function save() {
  isValidateTab.value = false
  if (tableInfo.value.data && tableInfo.value.data.length) {
    let isValidate = tableInfo.value.data.filter((item) => !item.isValidate)
    let assetResourceObj =
      proxy.$refs.associatedSubcardTableForm[
        Number(activeName.value)
      ].getAssociatedSubcardForm()
    if (!assetResourceObj.status) return
    tableInfo.value.data[Number(activeName.value)].assetResourceVOList =
      assetResourceObj.assetResourceVOList
    if (!isValidate.length) {
      let msg = []
      tableInfo.value.data.forEach((item) => {
        if (item.amountValidate) {
          msg.push(item.commonName)
        }
      })
      if (msg && msg.length) {
        proxy.$message.warning(
          `【${String(msg)}】的资金来源金额合计要与金额相等！`
        )
        return
      }
      let isFinanceAsset = tableInfo.value.data.filter(
        (item) => item.isFinanceAsset
      )
      if (
        !props.currentAccountingInterval &&
        isFinanceAsset.length === tableInfo.value.data.length
      ) {
        proxy.$message({
          type: 'error',
          duration: 3500,
          message: '未开启会计期间，请先开启会计期间!',
          showClose: true,
        })
      } else {
        if (props.type === 'store-build') {
          //入库
          let paramsData = tableInfo.value.data.map((item) => {
            item.orderSourceNo = item.orderNo
            item.orderSourceId = item.orderId
            item.orderSourceType = 66
            item.orderSourceDetailId = item.id
            return item
          })
          let params = proxy.$fn.deepClone(paramsData)
          params.forEach((item) => {
            item = setParams(item)
          })
          batchBuildByAssetStoreOrders(params).then((res) => {
            if (res.success) {
              showDialog.value = false
              emits('returnModify', false)
            }
          })
        } else if (props.type === 'store-store') {
          //入库-入库按钮
          let paramsData = tableInfo.value.data.map((item) => {
            item.orderSourceNo = item.orderNo
            item.orderSourceId = item.orderId
            item.orderSourceType = 66
            item.orderSourceDetailId = item.id
            return item
          })
          let params = proxy.$fn.deepClone(paramsData)
          params.forEach((item) => {
            item = setParams(item)
          })
          storeAssetStoreOrder(params).then((res) => {
            if (res.success) {
              showDialog.value = false
              emits('returnModify', false)
            }
          })
        } else if (props.type === 'receiving') {
          //收货
          let paramsData = tableInfo.value.data.map((item) => {
            item.orderSourceNo = item.orderNo
            item.orderSourceId = item.orderId
            item.orderSourceType = 15
            item.orderSourceDetailId = item.id
            return item
          })
          let params = proxy.$fn.deepClone(paramsData)
          params.forEach((item) => {
            item = setParams(item)
          })
          batchBuildByReceive(params)
            .then((res) => {
              if (res.success) {
                showDialog.value = false
                emits('returnModify', false)
              }
            })
            .catch(() => {})
        } else if (props.type === 'receiving-confirm') {
          //收货-确认
          let paramsData = tableInfo.value.data.map((item) => {
            item.orderSourceNo = item.orderNo
            item.orderSourceId = item.orderId
            item.orderSourceType = 15
            item.orderSourceDetailId = item.id
            return item
          })
          let params = proxy.$fn.deepClone(paramsData)
          params.forEach((item) => {
            item = setParams(item)
          })
          if (stockManageData && stockManageData.length) {
            let _stockManageData = stockManageData.value.map((item) => {
              return {
                orderSourceId: item.id,
              }
            })
            params = params.concat(_stockManageData)
          }
          confirmReceive(params)
            .then((res) => {
              if (res.success) {
                showDialog.value = false
                emits('returnModify', false)
              }
            })
            .catch(() => {})
        }
      }
    } else {
      if (formInfo.value.data.isValidate) {
        let commonNames = isValidate.map((item) => item.commonName)
        proxy.$message.warning(
          `标签【${commonNames}】的资金卡片必填或非法校验未通过，请检查！`
        )
        isValidateTab.value = true
      } else {
        validiteFun('save')
      }
    }
  }
}
function setParams(params) {
  if (
    !(
      params.assetCapitalSourceVOList && params.assetCapitalSourceVOList[0].code
    )
  ) {
    delete params.assetCapitalSourceVOList
  }
  if (
    params.assetAmortizationDeptVOList &&
    params.assetAmortizationDeptVOList.length
  ) {
    let amortizationDeptName = params.assetAmortizationDeptVOList.filter(
      (el) => el.amortizationDeptName
    )
    if (
      params.isFinanceAsset == 0 ||
      (params.isFinanceAsset == 1 && !amortizationDeptName.length)
    ) {
      delete params.assetAmortizationDeptVOList
    }
  }
  if (Number(params.isFinanceAsset) === 0) {
    let financeAsset = [
      'assetType',
      'assetTypeValue',
      'originalAmount',
      'netAmount',
      'deprMonthsLimit',
      'monthsUsed',
      'deprPreparation',
      'sumDeprAmount',
      'deprMethodType',
      'deprMethodTypeValue',
      'deprConvention',
      'deprConventionValue',
      'postingDate',
      'monthDeprRate',
      'monthDeprAmount',
    ]
    for (let key in params) {
      financeAsset.forEach((item) => {
        if (key === item) {
          params[key] = ''
        }
      })
    }
  }
  if (Number(params.isMaintenance) === 0) {
    let maintenance = [
      'warrantyType',
      'warrantyTypeValue',
      'warrantyStatus',
      'warrantyStatusValue',
      'maintenanceProviderName',
      'maintenanceProviderId',
      'maintenanceContactsName',
      'maintenanceContactsId',
      'maintenancePhone',
      'hospitalMaintainerUserName',
      'hospitalMaintainerUserId',
      'hospitalMaintainerPhone',
      'warrantyStartDate',
      'warrantyEndDate',
      'maintenanceContract',
      'maintenanceDescription',
    ]

    for (let key in params) {
      maintenance.forEach((item) => {
        if (key === item) {
          params[key] = ''
        }
      })
    }
  }
  if (Number(params.isMetering) === 0) {
    let measurement = [
      'measurementName',
      'professionalClassification',
      'professionalClassificationValue',
      'isMandatoryInspection',
      'isMandatoryInspectionValue',
      'pinyinCode',
      'measurementRange',
      'accuracy',
      'verificationPeriod',
      'verificationType',
      'verificationTypeValue',
      'verificationUnit',
      'mainParameter',
      'verificationDate',
      'validityDate',
      'verificationResult',
      'verificationResultValue',
      'verificationCertificateNumber',
    ]

    for (let key in params) {
      measurement.forEach((item) => {
        if (key === item) {
          params[key] = ''
        }
      })
    }
  }
  return params
}

function showFinanceFieldListItem(show, nameValue) {
  let fieldList = formInfo.value.financeInfoFieldList
  fieldList.forEach((item) => {
    if (nameValue === item.value) {
      item.show = show
    }
  })
}

function showFieldListItem(show, nameValue) {
  let fieldList = formInfo.value.baseInfoFieldList
  fieldList.forEach((item) => {
    if (nameValue === item.value) {
      item.show = show
    }
  })
}
async function beforeLeave(_activeName, _oldActiveName) {
  oldActiveNum.value = _oldActiveName
  console.log(_oldActiveName)
  let assetResourceObj =
    proxy.$refs.associatedSubcardTableForm[
      Number(_oldActiveName)
    ].getAssociatedSubcardForm()
  if (!assetResourceObj.status) {
    return reject()
  }
  if (!tableInfo.value.data[Number(_oldActiveName)].isValidate) {
    beforeLeaveData.value = {
      _activeName,
      _oldActiveName,
    }
    return reject()
  } else {
    beforeLeaveData.value = ''
    activeName.value = _activeName
    let assetResourceObj =
      proxy.$refs.associatedSubcardTableForm[
        Number(oldActiveNum.value)
      ].getAssociatedSubcardForm()
    tableInfo.value.data[Number(oldActiveNum.value)].assetResourceVOList =
      assetResourceObj.assetResourceVOList
    return true
  }
}
function handleClick(e) {
  if (
    beforeLeaveData.value &&
    !tableInfo.value.data[Number(beforeLeaveData.value._oldActiveName)]
      .isValidate
  ) {
    validiteFun('changeTab', beforeLeaveData.value._activeName)
    beforeLeaveData.value = ''
    return
  }

  let index = Number(activeName.value)
  if (index >= 0) {
    formInfo.value.data = tableInfo.value.data[index]
  }
  console.log(tableInfo.value.data)
  if (isValidateTab.value && e.paneName == activeName.value) {
    //切换标签页时是否需要先校验表单:点击了保存后，但是其他标签页并未校验，切换后需要立即校验
    proxy.$nextTick(() => {
      validiteFun()
    })
  }
}

function getCustomize() {
  let tableKey = ''
  if (props.type === 'receiving' || props.type === 'receiving-confirm') {
    //收货
    tableKey =
      'assetReceivingDetails-com.slip.spd.entity.vo.asset.AssetReceivingOrderDetailVO'
  } else if (props.type === 'store-build' || props.type === 'store-store') {
    //入库
    tableKey =
      'assetStoreOrderDetail-com.slip.spd.entity.vo.device.store.AssetStoreOrderDetailVO'
  }

  let param = {
    tableKey,
  }
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data
      filterInfo.value.query.customizeUserVO = data
      if (props.type === 'receiving' || props.type === 'receiving-confirm') {
        //收货
        getReceivingList()
      } else if (props.type === 'store-build' || props.type === 'store-store') {
        //入库-批量建卡/入库
        getStoreList()
      }
    }
  })
}
function getReceivingList() {
  //收货
  showFieldListItem(false, 'depotName')
  showFieldListItem(true, 'useDeptName')
  formInfo.value.baseInfoFieldList.forEach((item) => {
    if (item.value === 'accrualMark') {
      item['disabled'] = true
    }
  })
  filterInfo.value.query.queryMap.orderId.value = props.tableRow
    .map((item) => item.id)
    .toString()
  getReceiveDetailsAll(filterInfo.value.query).then((res) => {
    if (res && res.success) {
      let data = []
      if (props.type === 'receiving-confirm') {
        data = res.data.filter((item) => item.stockManage == 0)
        stockManageData.value = res.data.filter((item) => item.stockManage == 1)
      } else if (props.type === 'receiving') {
        data = res.data.filter(
          (item) =>
            item.status == 7 &&
            item.stockManage == 0 &&
            item.canBuildCardCalcQty !== 0
        )
      }
      if (data.length === 0) {
        proxy
          .$alert('没有可以批量建卡的数据', '提示', {
            confirmButtonText: '确定',
            type: 'warning',
            showCancelButton: false,
          })
          .then(() => {
            return
          })
        return
      }
      tableInfo.value.data = data.map((item) => {
        return {
          originalAmount: 0,
          monthsUsed: 0,
          sumDeprAmount: 0,
          deprMonthsLimit: '',
          isFinanceAsset:
            proxy.$store.state.permission.systemConfig
              .is_finance_asset_strategy,
          isMaintenance:
            proxy.$store.state.permission.systemConfig.is_maintenance_strategy,
          isMetering:
            proxy.$store.state.permission.systemConfig.is_metering_strategy,
          deprPreparation: 0,
          increaseType: 0, //增加方式默认为直接购入
          assetAmortizationDeptVOList: [{ amortizationDeptName: '' }],
          assetCapitalSourceVOList: [{ code: '1', amount: 0 }],
          assetName: item.commonName,
          assetCode: item.productCode,
          isValidate: false,
          ...item,
          residualRate: 0,
          inputTax: 0,
          residualAmount: 0,
        }
      })
      proxy.$nextTick(() => {
        getForm()
      })
    }
  })
}
function getStoreList() {
  //入库
  showFieldListItem(true, 'depotName')
  showFieldListItem(false, 'useDeptName')
  formInfo.value.baseInfoFieldList.forEach((item, index) => {
    if (item.value === 'accrualMark') {
      item['disabled'] = false
    }
  })
  filterInfo.value.query.queryMap.orderId.value = props.tableRow
    .map((item) => item.id)
    .toString()
  getAssetStoreOrderDetailCustomizeList(filterInfo.value.query).then((res) => {
    if (res && res.success) {
      let data = []
      if (props.type === 'store-store') {
        data = res.data
      } else if (props.type === 'store-build') {
        data = res.data.filter(
          (item) => item.status !== 7 && item.canBuildCardCalcQty !== 0
        )
      }
      if (data.length === 0) {
        proxy
          .$alert('没有可以批量建卡的数据', '提示', {
            confirmButtonText: '确定',
            type: 'warning',
            showCancelButton: false,
          })
          .then(() => {
            return
          })
        return
      }
      tableInfo.value.data = data.map((item) => {
        return {
          originalAmount: 0,
          monthsUsed: 0,
          sumDeprAmount: 0,
          deprMonthsLimit: '',
          isFinanceAsset:
            proxy.$store.state.permission.systemConfig
              .is_finance_asset_strategy,
          isMaintenance:
            proxy.$store.state.permission.systemConfig.is_maintenance_strategy,
          isMetering:
            proxy.$store.state.permission.systemConfig.is_metering_strategy,
          deprPreparation: 0,
          increaseType: 0, //增加方式默认为直接购入
          assetCapitalSourceVOList: [{ code: '1', amount: 0 }],
          assetAmortizationDeptVOList: [{ amortizationDeptName: '' }],
          assetName: item.commonName,
          assetCode: item.productCode,
          isValidate: false,
          ...item,
          residualRate: 0,
          inputTax: 0,
          residualAmount: 0,
        }
      })
      proxy.$nextTick(() => {
        getForm()
      })
    }
  })
}
function getForm() {
  tableInfo.value.data.forEach((data) => {
    if (props.type === 'receiving' || props.type === 'receiving-confirm') {
      //收货
      data['useStatus'] = 2
      data['accrualMark'] = 0
      props.tableRow.forEach((el) => {
        if (data.orderId === el.id) {
          data['manageDeptName'] = el.deptName
          data['manageDeptId'] = el.deptId
          data['useDeptId'] = el.deptId
          data['useDeptName'] = el.deptName
        }
      })
    }
    if (props.type === 'store-build' || props.type === 'store-store') {
      //入库
      data['useStatus'] = 1
      data['accrualMark'] = 1
      data['depotName'] = data.depotName
      data['depotId'] = data.depotId
    }
    data['postingDate'] = moment(new Date()).format('YYYY-MM-DD')
    data['classifyTypeValue'] = data.assetTypeValue
    data['classifyType'] = data.assetType
    data['financialClassifyTypeValue'] = data.financeTypeValue
    data['financialClassifyType'] = data.financeType
    data['assetName'] = data.commonName
    data['standard'] = data.standard
    data['brandName'] = data.brandName
    data['mark'] = data.trademark
    if (data.financialClassifyTypeValue) {
      data['isFinanceAsset'] = 1
      if (
        data.assetAmortizationDeptVOList.length &&
        !changeAmortizationDeptNameFlag.value &&
        Number(data.useStatus) === 2
      ) {
        data.assetAmortizationDeptVOList[
          data.assetAmortizationDeptVOList.length - 1
        ].amortizationDeptName = data.useDeptName

        data.assetAmortizationDeptVOList[
          data.assetAmortizationDeptVOList.length - 1
        ].amortizationDeptId = data.useDeptId

        data.assetAmortizationDeptVOList[
          data.assetAmortizationDeptVOList.length - 1
        ].amortizationRate = 100
      }
      data.netAmount = utils.Subtr(
        utils.Subtr(
          utils.Subtr(data.originalAmount || 0, data.residualAmount || 0),
          data.sumDeprAmount || 0
        ),
        data.deprPreparation || 0
      )
    }
    data['unitId'] = data.unitId === -2 ? '' : data.unitId
    data['primitiveOriginalAmount'] = data.price
    data['qty'] = 1
    data['temporaryPurch'] = 0
    data['originalAmount'] = data.primitiveOriginalAmount
    data['assetType'] = data.preAssetType === -2 ? '' : data.preAssetType
    //没有供应商的可以修改，有供应商的不可修改
    if (data.supplierName) {
      data.disabledSupplier = true
    } else {
      data.disabledSupplier = false
    }
    if (!changeAmountFlag.value) {
      data['assetCapitalSourceVOList'][
        data.assetCapitalSourceVOList.length - 1
      ]['amount'] = data.primitiveOriginalAmount
    }
  })
  formInfo.value.data = tableInfo.value.data[0]
}
</script>

<style scoped lang="scss">
:deep(.box-scroll-y) {
  height: calc(100% - 20px);
}
.i-more-disabled {
  cursor: not-allowed;
}
.i-more {
  background-color: #ffffff;
  cursor: pointer;
  height: 26px;
}
.tabs {
  :deep(.el-tabs__item) {
    // margin-right: 0px;
    width: 250px;
    word-wrap: break-word;

    word-break: normal;
  }
  :deep(.el-tabs__item.is-left) {
    text-align: center;
  }
  :deep(.el-tabs__item) {
    height: 100%;
    // padding: 0;
  }
  :deep(.el-tabs__nav) {
    word-wrap: break-word;
    white-space: normal;
  }
  :deep(.el-tabs__header.is-left) {
    margin-right: 0px;
  }
  :deep(.el-tabs__content) {
    height: 100%;
  }
}
.el-tab-pane-li {
  height: 22px;
  line-height: 22px;
  text-align: left;
}
.commonName {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  -o-text-overflow: ellipsis;
}
.el-tabs--left.el-tabs--card :deep(.el-tabs__item.is-left.is-active) {
  border-right-color: #e4e7ed;
}
:deep(.el-tabs__item.is-active) {
  color: #606266;
  background-color: #d5e5f3;
}
</style>
